Update JSON value with ijson in Python
Asked Answered
O

1

6

I am working on a very big JSON file, and I decided to use the ijson library.

Now I want to update some value in this JSON file, but I don't know how.

For example, from:

{"age": 25, "gender": "M"}

update to:

{"age": 30, "gender": "F"}

by using the ijson library.

Osteology answered 4/5, 2017 at 20:24 Comment(0)
B
1

Refer the examples in https://pypi.python.org/pypi/ijson/. For editing you can simply use the json library. First load/deserialize the json object then edit and finally use the dump method to update your json file.

Ban answered 4/5, 2017 at 20:37 Comment(2)
Thanks, yes, I already thought this, but the problem is that if the file is very large (Gbs), only load the file by using json library requires a lot of time. Is there a way to address this issue?Osteology
You can use pandas dataframes or graphlab SFrame to load large json files. Also both the libraries are more stable than ijson streaming.Ban

© 2022 - 2024 — McMap. All rights reserved.