there's a json obj:
{'key1': 'val1', 'key2': "{"key3": ["val3"]}"}
how to parse json string and json obj in the same json obj
json.load() => AttributeError: 'str' object has no attribute 'read' json.loads() => JSONDecodeError: Expecting ',' delimiter: line 1 column 232 (char 231)
CodePudding user response:
Pretty sure you want to use JSON library as Himanshu suggested.
I think this will answer your questions:
CodePudding user response:
Easiest way is to format the dict with multi-line string, then use json.dumps:
d = {'key1': 'val1', 'key2': """{"key3": ["val3"]}"""}
json.dumps(d) # a new json string
json.loads(d["key2"]) # the obj