Skip to content

Modifying the DOM of nested arrays of json objects #2823

Answered by nlohmann
WBIGitHub asked this question in Q&A
Discussion options

You must be logged in to vote

I don't fully understand your issue, so I try to answer as much as possible:

  1. Assuming your value is parsed to a json variable j, then j[FOO][BAR] gives you a reference to the value. For arrays, you need to provide integer indices.
  2. The library stores the JSON value in a tree without references: every value can be changed independently. In fact, you can see the library as syntactic sugar around a mix of a std::vector (for arrays) and std::map (for objects).
  3. You can erase elements just like in other STL containers, see https://json.nlohmann.me/api/basic_json/erase.

Your overall idea should be possible without any headaches with this library.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@WBIGitHub
Comment options

Answer selected by WBIGitHub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants