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

json2: decode array of arrays #22362

Closed
esquerbatua opened this issue Sep 30, 2024 · 1 comment · Fixed by #22365
Closed

json2: decode array of arrays #22362

esquerbatua opened this issue Sep 30, 2024 · 1 comment · Fixed by #22365
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. Modules: x.json2 Bugs related to *only* x.json2 (the pure V implementation) Status: Confirmed This bug has been confirmed to be valid by a contributor.

Comments

@esquerbatua
Copy link
Contributor

esquerbatua commented Sep 30, 2024

Describe the bug

As json, in x.json2, we need the same functionality, decoding arrays of arrays it's not working

Reproduction Steps

module main

import json
import x.json2

pub struct Data {
	name string
	data [][]f64
}

fn main() {
	json_data := '{"name":"test","data":[[1,2,3],[4,5,6]]}'
	info := json.decode(Data, json_data)!
	println(info)

	info2 := json2.decode<Data>(json_data)!
	println(info2)
}

Expected Behavior

Data{
    name: 'test'
    data: [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
}
Data{
    name: 'test'
    data: [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
}

Current Behavior

Data{
    name: 'test'
    data: [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
}
Data{
    name: 'test'
    data: []
}

Possible Solution

Implement decode of arrays of arrays in json2

Additional Information/Context

No response

V version

V full version: V 0.4.7 372a402.2db53a4

Environment details (OS name and version, etc.)

V full version: V 0.4.7 372a402.2db53a4
OS: linux, Ubuntu 24.04.1 LTS
Processor: 16 cpus, 64bit, little endian, AMD Ryzen 7 7840HS w/ Radeon 780M Graphics

vexe: /home/esquerbatua/git/v/v
vexe mtime: 2024-09-27 21:16:15

vroot: OK, value: /home/esquerbatua/git/v
VMODULES: OK, value: /home/esquerbatua/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.43.0
Git vroot status: weekly.2024.39-30-g2db53a4b (20 commit(s) behind V master)
.git/config present: true

CC version: cc (Ubuntu 13.2.0-23ubuntu4) 13.2.0
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

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.

@esquerbatua esquerbatua 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 Sep 30, 2024
@felipensp felipensp added the Modules: x.json2 Bugs related to *only* x.json2 (the pure V implementation) label Sep 30, 2024
@esquerbatua esquerbatua changed the title json2: decode & encode array of arrays json2: decode array of arrays Sep 30, 2024
@esquerbatua esquerbatua added Modules: x.json2 Bugs related to *only* x.json2 (the pure V implementation) and removed Modules: x.json2 Bugs related to *only* x.json2 (the pure V implementation) labels Sep 30, 2024
@esquerbatua
Copy link
Contributor Author

It's working with raw_decode:

module main

import json
import x.json2

pub struct Data {
	name string
	data [][]f64
}

fn main() {
	json_data := '{"name":"test","data":[[1,2,3],[4,5,6]]}'
	info := json.decode(Data, json_data)!
	println(info)
	info2 := json2.decode<Data>(json_data)!
	println(info2)
	raw_info2 := json2.raw_decode(json_data)!
	println(raw_info2)
}

outputs:

Data{
    name: 'test'
    data: [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
}
Data{
    name: 'test'
    data: []
}
{"name":"test","data":[[1,2,3],[4,5,6]]}

@felipensp felipensp added the Status: Confirmed This bug has been confirmed to be valid by a contributor. label Sep 30, 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: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. Modules: x.json2 Bugs related to *only* x.json2 (the pure V implementation) Status: Confirmed This bug has been confirmed to be valid by a contributor.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants