Python: If you have multiple json files, is it possible to read them all?

Asked 2 years ago, Updated 2 years ago, 13 views

I'm studying Python these days

I'm studying the json writing, reading, and writing part in Python, and I know the part where I read one json file and get the value inside, but if there are several json files, is it possible to read all of them?

For example, if you have four json files that contain "Book Name, Author, Serial Number" (all four have different values)

Is there a way to read all four files and pick out a specific book or serial number?

python

2022-09-20 19:27

1 Answers

with open('./book2reum.json', 'r') as f:
    book = json.load(f)
with open('./jackga.json', 'r') as f:
    jackga = json.load(f)
with open('./serial.json', 'r') as f:
   serial = json.load(f)

# If you want to get it from a book,
>>> book ['Import Key Value']

If you want to get it from #jackga,
>>> jackga ['Import Key Value']

You just have to load several. I don't know if you understand.


2022-09-20 19:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.