I have a json structure like
{
"a": "1",
"b": "2",
"c": {
"d": "3"
}
}
What I want is to only keep the 1st level of the json, i.e. remove if 1st level's value is not a string, so I have a program like
import json
s = ''' {
"a": "1",
"b": "2",
"c": {
"d": "3"
} } '''
data = json.loads(s)
ret = {}
for k, v in data.items():
if (isinstance(v, basestring)):
ret[k] = v
print json.dumps(ret)
Since I need to process huge amount of json string like that, I am looking for if any fastest way or more elegant way to do the same thing in Python