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: allow anon struct as decode type #22228

Merged
merged 4 commits into from
Sep 17, 2024

Conversation

felipensp
Copy link
Member

@felipensp felipensp commented Sep 15, 2024

Fix #21703

import json

fn main() {
	json_text := '{ "a": "b" }'
	b := json.decode(struct {
		a string
	}, json_text)!.a
	assert dump(b) == 'b'
}

@JalonSolov
Copy link
Contributor

Really should be improving x.json2 so json can be retired...

@Delta456
Copy link
Member

It is better to support passing anonymous structs as parameters in general not just json.

@JalonSolov
Copy link
Contributor

If they're going to be supported at all, then yes, they should be supported in general.

@felipensp
Copy link
Member Author

But it's about anon struct declaration, not initialization.

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman marked this pull request as ready for review September 17, 2024 12:32
@spytheman spytheman merged commit 97c9f5f into vlang:master Sep 17, 2024
78 checks passed
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.

Allows annonymous struct type to be passed as args
4 participants