Json data:
{
"options": {
"name": "aaa",
"count": 20,
"a1": 30
},
"PC": {
"processor": "Intel",
"os": "windows"
}
}
Pattern:
{
"options": {
"name": "string",
"count": "integer",
"a1": "integer"
},
"PC": {
"processor": "string",
"os": "string"
}
}
How to check that all keys are there and their type is the same?
import json
data = '{"options": {"name": "aaa","count": 20,"a1": 30},"PC": {"processor": "Intel","os": "windows"}}'
pattern = '{"options": {"name": "string","count": "integer","a1": "integer"},"PC": {"processor": "string","os": "string"}}'
json_data = json.loads(data)
json_pattern = json.loads(pattern)
for key in json_pattern.keys():
if key not in json_data:
print("Error: %s" % key)
print("end")
json_pattern.keys()
return only options
and PC
, but i need name, count, a1, processor, os
too.
And one more question, how to know that PC
and options
is variable which contains another variables?
Sorry for my english.