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: make encode number cJson compatible #22419

Merged
merged 1 commit into from
Oct 6, 2024

Conversation

kbkpbot
Copy link
Contributor

@kbkpbot kbkpbot commented Oct 6, 2024

fix #22363

import json
import x.json2

pub struct Data {
	float64 f64
}

fn main() {
	data := Data{1.0}

	info_encoded := json.encode(data)
	println(info_encoded)
	info2_encoded := json2.encode(data)
	println(info2_encoded)
	assert info2_encoded == '{"float64":1}'  // not '{"float64":1.0}' anymore
}

Comment on lines +602 to +604
// TODO:cjson Try 15 decimal places of precision to avoid nonsignificant nonzero digits
// If not, print with 17 decimal places of precision
// strconv.f64_to_str_l try max 18 digits instead.
Copy link
Member

Choose a reason for hiding this comment

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

I think that can be done with return '${value:.15f}', but I have not tried.

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 merged commit e83b0d2 into vlang:master Oct 6, 2024
67 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.

json2: encode array of arrays, bad encoding 1.0 -> should be 1
2 participants