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

x.json2: decode array #21186

Merged
merged 1 commit into from
Apr 6, 2024
Merged

x.json2: decode array #21186

merged 1 commit into from
Apr 6, 2024

Conversation

felipensp
Copy link
Member

@felipensp felipensp commented Apr 4, 2024

Fix #21168

Added generic way to decode a JSON array string into a array of generic type.

import x.json2


pub struct Value {
	value string
}

pub struct Value2 {
	value string
}

fn main() {
	println(json2.decode_array[Value]('[{"value": "abc"}, {"value": "def"}]')!)
	println(json2.decode_array[Value2]('[{"value": "abc"}, {"value": "def"}]')!)
}

@ttytm
Copy link
Member

ttytm commented Apr 4, 2024

Why not making it part of decode?

@felipensp
Copy link
Member Author

Why not making it part of decode?

Must investigate a way to decode []T to T, it seems we can't do it at the moment. This was the point.

@felipensp felipensp marked this pull request as ready for review April 5, 2024 21:49
@spytheman spytheman merged commit 9d88984 into vlang:master Apr 6, 2024
42 checks passed
@felipensp felipensp deleted the json_decode_array branch April 6, 2024 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[x.json2] Decoding array type panics
3 participants