Python:两个JSON对象的深度合并

2024-06-02 02:37:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试用Python中的几个对象构建一个单独的JSON对象。在

lineage1 = {"name":"rob", "children":[{"name":"henry", "children":[{"name":"johnny", "age":5}]}]}
lineage2 = {"name":"rob", "children":[{"name":"henry", "children":[{"name":"susan", "age":3}]}]}
lineage3 = {"name":"rob", "children":[{"name":"shannon", "children":[{"name":"casey", "age":13}]}]}
lineage4 = {"name":"rob", "children":[{"name":"shannon", "children":[{"name":"alfred", "age":9}]}]}

我想在(祖父,父母,孩子)周围集合。E、 g

^{pr2}$

有没有一种圆滑的Python式的方法?这将以流式方式执行,因为record进来了,我想将它们合并到“master”json中。谢谢你的帮助。在


Tags: 对象namejsonageshannonrobchildrensusan