I have a http server and I would like to handle JSON responses to overwrite a JSON file, and I want to be able to parse any amount of data and structure.
So my JSON data could look like this:
{
"property1": "value",
"properties": {
"property1": 1,
"property2": "value"
}
}
Or it can look like this:
{"property": "value"}
I would like to iterate through each property, and if it already exists in the JSON file, overwrite it's value, otherwise append it to the JSON file.
I have tried using map
but it doesn't seem to support indexing. I can search for specific properties by using map["property"]
but the idea is that I don't know any of the JSON data yet.
How can I (without knowing the struct) iterate through each property and print both its property name and value?