How to merge two json string in Python?

后端 未结 6 2078
醉酒成梦
醉酒成梦 2020-12-08 10:20

I recently started working with Python and I am trying to concatenate one of my JSON String with existing JSON String. I am also working with Zookeeper so I get the existing

6条回答
  •  一整个雨季
    2020-12-08 11:08

    As of Python 3.5, you can merge two dicts with:

    merged = {**dictA, **dictB}
    

    (https://www.python.org/dev/peps/pep-0448/)

    So:

    jsonMerged = {**json.loads(jsonStringA), **json.loads(jsonStringB)}
    asString = json.dumps(jsonMerged)
    

    etc.

提交回复
热议问题