I was looking through a JSON file that contained multiple dictionary entries similar to the one below. I am in python and cannot find a way to decipher this, and cannot find anything on Google about this. It seems to me to be another dictionary, inside a string, with backslashes. I'm sorry I can't be more descriptive as I am not even sure what to call this.
{"restrictions":"[{\"type\":\"whitelist\",\"firstFilter\":{\"finder\":\"Criteria\",\"minimum\":\"800000\"}}]"}
I want to know what type of entry this is called or how I can decode it.
CodePudding user response:
{
"restrictions": "[
{
\"type\": \"whitelist\",
\"firstFilter\": {
\"finder\":\"Criteria\",
\"minimum\":\"800000\"
}
}
]"
}
This is a JSON
object, inside it there is a str
ing that contains JSON
.
In Python you can decode it with the json
library, in this case with json.loads()
.
>>> my_dict = {"restrictions":"[{\"type\":\"whitelist\",\"firstFilter\":{\"finder\":\"Criteria\",\"minimum\":\"800000\"}}]"}
>>> my_json_string = my_dict["restrictions"]
>>> import json
>>> json.loads(my_json_string)
Try this, it should work, the result is:
[{'type': 'whitelist', 'firstFilter': {'finder': 'Criteria', 'minimum': '800000'}}]
It seems to me to be another dictionary, inside a string, with backslashes
The backslashes are used to escape some characters, not only in JSON
:
>>> "And they said: "Hello!"" # This will give you an error
>>> "And they said: \"Hello!\"" # This is ok