Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json [raw] no error message given when fails #19801

Open
einar-hjortdal opened this issue Nov 7, 2023 · 1 comment · May be fixed by #21184
Open

json [raw] no error message given when fails #19801

einar-hjortdal opened this issue Nov 7, 2023 · 1 comment · May be fixed by #21184
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Fixed in x.json2 A JSON related issue, that is fixed in `x.json2` module. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. Nicer V Errors Bugs/feature requests, related to improving V error messages.

Comments

@einar-hjortdal
Copy link
Contributor

einar-hjortdal commented Nov 7, 2023

Describe the bug

import json

struct TestStruct {
    metadata string [raw]
}

json_object := '
{
  "metadata": {
    "topLevelProperty": {
      "nestedProperty1": "Value 1",
      "nestedProperty2": "Value 2",
      "nestedProperty3": {
        "subNestedProperty1": "Sub-Value 1",
        "subNestedProperty2": "Sub-Value 2"
      }
    }
  }
}'

// This string is wrapped in single quotes
stringified_json := '"{\n  \"metadata\": {\n    \"topLevelProperty\": {\n      \"nestedProperty1\": \"Value 1\",\n      \"nestedProperty2\": \"Value 2\",\n      \"nestedProperty3\": {\n        \"subNestedProperty1\": \"Sub-Value 1\",\n        \"subNestedProperty2\": \"Sub-Value 2\"\n      }\n    }\n  }\n}"'

stringified_json_no_single_quotes := "{\n  \"metadata\": {\n    \"topLevelProperty\": {\n      \"nestedProperty1\": \"Value 1\",\n      \"nestedProperty2\": \"Value 2\",\n      \"nestedProperty3\": {\n        \"subNestedProperty1\": \"Sub-Value 1\",\n        \"subNestedProperty2\": \"Sub-Value 2\"\n      }\n    }\n  }\n}"

test_one := json.decode(TestStruct, json_object)!
test_two := json.decode(TestStruct, stringified_json)!
test_three := json.decode(TestStruct, stringified_json_no_single_quotes)!

println(test_one)
println(test_two) // empty string, no errors
println(test_three)

Reproduction Steps

Run code above

Expected Behavior

Error returned by test_two := json.decode(TestStruct, stringified_json)!

Current Behavior

No error is returned, the json object is lost, an empty string is the result

Possible Solution

No response

Additional Information/Context

No response

V version

Current V version: V 0.4.2 a92700e, timestamp: 2023-11-06 20:09:05 +0200

Environment details (OS name and version, etc.)

V full version: V 0.4.2 https://github.com/vlang/v/commit/95509cf8fbd30e723da6d6aae9872475cdfef026.a92700e
OS: linux, Linux version 5.14.0-284.30.1.el9_2.x86_64 ([email protected]) (gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4), GNU ld version 2.35.2-37.el9) #1 SMP PREEMPT_DYNAMIC Fri Sep 15 08:06:33 UTC 2023
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz

getwd: /home/coachonko
vexe: /home/coachonko/.local/lib64/v/v
vexe mtime: 2023-11-06 21:32:00

vroot: OK, value: /home/coachonko/.local/lib64/v
VMODULES: OK, value: /home/coachonko/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.39.3
Git vroot status: weekly.2023.43-126-ga92700e9
.git/config present: true

CC version: cc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4)
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@einar-hjortdal einar-hjortdal added the Bug This tag is applied to issues which reports bugs. label Nov 7, 2023
@ArtemkaKun ArtemkaKun added Nicer V Errors Bugs/feature requests, related to improving V error messages. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. labels Nov 7, 2023
@enghitalo enghitalo added the Fixed in x.json2 A JSON related issue, that is fixed in `x.json2` module. label Nov 3, 2024
@enghitalo enghitalo self-assigned this Nov 3, 2024
@enghitalo
Copy link
Contributor

@enghitalo Include tests in x.json2.decoder2

import x.json2.decoder2 as json
// import x.json2 as json

struct TestStruct {
    metadata string @[raw]
}

json_object := '
{
  "metadata": {
    "topLevelProperty": {
      "nestedProperty1": "Value 1",
      "nestedProperty2": "Value 2",
      "nestedProperty3": {
        "subNestedProperty1": "Sub-Value 1",
        "subNestedProperty2": "Sub-Value 2"
      }
    }
  }
}'

// This string is wrapped in single quotes
stringified_json := '"{\n  \"metadata\": {\n    \"topLevelProperty\": {\n      \"nestedProperty1\": \"Value 1\",\n      \"nestedProperty2\": \"Value 2\",\n      \"nestedProperty3\": {\n        \"subNestedProperty1\": \"Sub-Value 1\",\n        \"subNestedProperty2\": \"Sub-Value 2\"\n      }\n    }\n  }\n}"'

stringified_json_no_single_quotes := "{\n  \"metadata\": {\n    \"topLevelProperty\": {\n      \"nestedProperty1\": \"Value 1\",\n      \"nestedProperty2\": \"Value 2\",\n      \"nestedProperty3\": {\n        \"subNestedProperty1\": \"Sub-Value 1\",\n        \"subNestedProperty2\": \"Sub-Value 2\"\n      }\n    }\n  }\n}"

test_one := json.decode[TestStruct](json_object)!
test_two := json.decode[TestStruct](stringified_json)!
test_three := json.decode[TestStruct](stringified_json_no_single_quotes)!

println(test_one)
println(test_two) // empty string, no errors
println(test_three)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Fixed in x.json2 A JSON related issue, that is fixed in `x.json2` module. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. Nicer V Errors Bugs/feature requests, related to improving V error messages.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants