I have a JSON
file like this:
{
"top_key1": {
"bottom.key1": "one",
"bottom.key2": "two"
},
"top_key2": [
"bottom.key1": "one",
"bottom.key2": "two",
]
}
And I need to store in a data structure that won't allow me to store a key with a period (.
) on it. How can I traverse this JSON
structure so I replace every .
occurrence by _
? The final result would be:
{
"top_key1": {
"bottom_key1": "one",
"bottom_key2": "two"
},
"top_key2": [
"bottom_key1": "one",
"bottom_key2": "two",
]
}
The JSON
file can be nested several (unknown) times and there can be .
on values also, but I don't want them replaced by _
. Also, value of "top_key2" is a list, which should be preserved.