I’m trying to avoid the inverse of this question
Suppose I have a valid JSON string that I want to make part of a larger JSON object. The most straight forward solution is parsing the string as dict, then dumping it again to json:
import json
json_str = '{"name": "Alice", "age": 30}'
# Write the JSON-encoded string to a string
new_json_str = json.dumps({"foo": "bar", "user": json.loads(json_str)})
Is the parsing – dumping round trip avoidable?