-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
x.json2 fails to decode a map with number keys #21683
Labels
Bug
This tag is applied to issues which reports bugs.
Modules: x.json2
Bugs related to *only* x.json2 (the pure V implementation)
Comments
spytheman
added
Bug
This tag is applied to issues which reports bugs.
Modules: JSON
Bugs/feature requests, that are related to `json` and `x.json2` modules.
labels
Jun 15, 2024
Note that a more manual version of the program works: module main
import x.json2
const data = '
{
"comments": {
"26788945": {
"id": "26788945",
"message": "some comment 1"
},
"26788946": {
"id": "26788946",
"message": "some comment 2"
},
"26788947": {
"id": "26788947",
"message": "some comment 3"
}
}
}
'
struct Comment {
id string
message string
}
struct Comments {
mut:
comments map[string]Comment
}
fn main() {
mut root := Comments{}
for k, v in json2.raw_decode(data)!.as_map()['comments']!.as_map() {
comment := json2.decode[Comment](v.str())!
root.comments[k] = comment
}
println(root)
} producing:
I expected that |
Using module main
import json
const data = '
{
"comments": {
"26788945": {
"id": "26788945",
"message": "some comment 1"
},
"26788946": {
"id": "26788946",
"message": "some comment 2"
},
"26788947": {
"id": "26788947",
"message": "some comment 3"
}
}
}
'
struct Comment {
id string
message string
}
struct Comments {
mut:
comments map[string]Comment
}
fn main() {
root := json.decode(Comments, data)!
println(root)
} |
spytheman
added
Modules: x.json2
Bugs related to *only* x.json2 (the pure V implementation)
and removed
Modules: JSON
Bugs/feature requests, that are related to `json` and `x.json2` modules.
labels
Jun 15, 2024
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.
Modules: x.json2
Bugs related to *only* x.json2 (the pure V implementation)
V doctor:
What did you do?
v -g -o vdbg cmd/v && vdbg j4.v
What did you expect to see?
A non empty structure
What did you see instead?
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.
The text was updated successfully, but these errors were encountered: