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 incorrectly serialized #2198

Closed
avin-kavish opened this issue Jun 18, 2020 · 3 comments
Closed

JSON incorrectly serialized #2198

avin-kavish opened this issue Jun 18, 2020 · 3 comments
Labels
kind: question state: needs more info the author of the issue needs to provide more details

Comments

@avin-kavish
Copy link

avin-kavish commented Jun 18, 2020

I wrote the JSON to a file like this,

ofstream file("foo.json");
file << foo->serialize() << endl;

(serialize() returns nholmann::json)

and the file ended up looking like,

"[[{\"x\":27,\"y\":0},{\"x\":27,\"y\":1}],[{\"x\":27,\"y\":0}, ....

I think it gets serialized twice and ends up writing a string. But if I pipe serialize() to std::cout the console output is formatted properly.

I would want it to look like

[[{"x":27,"y":0},{"x":27,"y":1}],[{"x":27,"y":0},

How can I achieve this?

@avin-kavish avin-kavish changed the title JSON written to file as a string JSON incorrectly serialized Jun 18, 2020
@nlohmann
Copy link
Owner

That looks odd. Can you make sure serialize() returns a json?

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Jun 18, 2020
@avin-kavish
Copy link
Author

Whoops, I had put .dump() in that function but it compiled because string can be casted to json I guess...

Thanks.

@nlohmann
Copy link
Owner

That explains the double escaping. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question state: needs more info the author of the issue needs to provide more details
Projects
None yet
Development

No branches or pull requests

2 participants