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

STL containers are always serialized to a nested array like [[1,2,3]] #1013

Closed
fred777 opened this issue Mar 14, 2018 · 2 comments
Closed

STL containers are always serialized to a nested array like [[1,2,3]] #1013

fred777 opened this issue Mar 14, 2018 · 2 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@fred777
Copy link

fred777 commented Mar 14, 2018

Bug Report

I'm using the single-header json.hpp (v3.1.1) and I am struggling with serializing stl containers:

auto tojson = nlohmann::json{ std::forward_list<double>{1,2,3} };
cout << tojson;

Expected: [1,2,3]
Got instead: [[1,2,3]]

It's the same for other STL containers like vector, list, initializer_list, ...

Did I miss something?

Compiler: Visual C++ 2017 (v15.6.1)
OS: Windows 10 x64

@nlohmann
Copy link
Owner

This is due to the outer-most braces which are interpreted as array. Try

nlohmann::json tojson = std::forward_list<double>{1,2,3};
cout << tojson;

@fred777
Copy link
Author

fred777 commented Mar 14, 2018

Thanks! You saved my day 👍

@fred777 fred777 closed this as completed Mar 14, 2018
@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Mar 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants