I am very new to Python, I need to merge two json file with multiple json object based on "Id".
File1.json
{"id": 1, "name": "Ault", "class": 8, "email": "[email protected]"}
{"id": 2, "name": "john", "class": 8, "email": "[email protected]"}
{"id": 3, "name": "josh", "class": 8, "email": "[email protected]"}
{"id": 4, "name": "emma", "class": 8, "email": "[email protected]"}
File2.json
{"id": 4, "math": "A", "class": 8, "physics": "D"}
{"id": 2, "math": "B", "class": 8, "physics": "C"}
{"id": 3, "math": "A", "class": 8, "physics": "A"}
{"id": 1, "math": "C", "class": 8, "physics": "B"}
I have tried both json.loads(jsonObj) and json.load(path). Both throw errors. I know both files are not a valid json as a whole (combined), but each line in a file is a valid json. I want to read line by line and merge both.
list1 = [json.loads(line) for line in open(path)]and then you can post your attempt at merging (hint: plenty of questions on merging dicts here on SO)