Oct-10-2022, 03:41 AM
(Oct-09-2022, 09:41 AM)ibreeden Wrote:(Oct-09-2022, 07:39 AM)rob101 Wrote: Okay, so the jason file has yet to be translated; I'll work on that.I think there is nothing wrong with the json. You should use the json module for the translating.
(Oct-09-2022, 07:22 AM)Calli Wrote: NameError: name 'data' is not definedOf course, you should define data.
The whole problem can be solved in 4 lines of code.
import json # First import the json module. f = open('df.json', 'r') # You did that right. data = json.load(f) # Now "data" contains the content of the file. According to what you # showed us, it is a nested dictionary. # You can now print it like rob101 showed you. print(f"amount: {data['_source']['amount']}, email: {data['_source']['email']}, mobile: {data['_source']['mobile']}, accountOwner: {data['_source']['accountOwner']}")
Output:amount: 300, email: [email protected], mobile: 100000012457, accountOwner: Tom Hank
This is the error I am getting
Traceback (most recent call last): File "/media/redhat/test/Shodan/data/df.py", line 4, in <module> data = json.load(f) File "/usr/lib/python3.10/json/__init__.py", line 293, in load return loads(fp.read(), File "/usr/lib/python3.10/json/__init__.py", line 346, in loads return _default_decoder.decode(s) File "/usr/lib/python3.10/json/decoder.py", line 340, in decode raise JSONDecodeError("Extra data", s, end) json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 1289)