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

Documentation or feature request. #763

Closed
deathly809 opened this issue Oct 1, 2017 · 3 comments
Closed

Documentation or feature request. #763

deathly809 opened this issue Oct 1, 2017 · 3 comments

Comments

@deathly809
Copy link

Is it possible to flatten fixed sized arrays to a single array?

Serialize

std::vector<Vec3> points = {{1,2,3} , {4,5,6} };
{
  "points" : [
        1,
        2,
        3,
        4,
        5,
        6
  ]
}

Deserialize

{
  "points" : [
        1,
        2,
        3,
        4,
        5,
        6
  ]
}
std::vector<Vec3>  points = { {1,2,3} {4,5,6} };
@nlohmann
Copy link
Owner

nlohmann commented Oct 2, 2017

This feature is too specific to be added to this general-purpose JSON library. You may want to do the flattening/unflattening outside the library (see https://stackoverflow.com/questions/17294629/merging-flattening-sub-vectors-into-a-single-vector-c-converting-2d-to-1d for examples) and store std::vector<int> inside the JSON value. To avoid copies, you can use get_ref (see https://nlohmann.github.io/json/classnlohmann_1_1basic__json_afbd800010b67619463c0fce6e74f7878.html#afbd800010b67619463c0fce6e74f7878).

@deathly809
Copy link
Author

Thanks. I will give it a try.

@nlohmann
Copy link
Owner

nlohmann commented Oct 2, 2017

I'm closing the issue. If you experience any problems, feel free to ask and I will reopen it.

@nlohmann nlohmann closed this as completed Oct 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants