I am developing a C++ application that uses rapidjson to access information from a file that is in json format.
This file has a structure like the following:
{
"field_1" : "val_1",
"field_2" : "val_2",
"section_1" : {
"field_11" : 1,
"field_12" : "one text",
"field_13" : ["one", "two", "three"]
},
"section_2": {
"field_21" : [ 1, 2, 3, 4, 5 ],
"field_22" : true,
"field_23" : 3.14,
"field_24" : [ 1.00, 2.00, 3.00],
"field_25" : [ true, false, true ]
},
}
The name of the fields is not fixed or known a priori. I need to obtain a vector with the name of all the fields there are in the json.
For example, something like this:
<pre>std::vector <std::string> json_fields;
json_fields = [ "field_1", "field_2", "section_1", "field_11", "field_12",
"field_13", "section_2", "field_21", "field_22", , "field_21", "field_22",
"field_23", "field_24",, "field_25" ]
Or something similar, so that the C++ application can know what name the fields that have been defined in the json have, since its name is not known a priori.
Is it possible to do this with rapidjson?
Any comments or suggestions are welcome.
What I have tried:
I am able to get the value from a field using rapidjson if I know its name, but I will not know the names and I need to get the names.
I have read some tutorial that explain how to get the value of a field in the json or how to modify it, but they do not explain if it is possible to get the list with all names and how to get this.