Python Forum
Extract only certain text which are needed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extract only certain text which are needed
#13
(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 defined
Of 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)
Reply


Messages In This Thread
RE: Extract only certain text which are needed - by Calli - Oct-10-2022, 03:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  extract only text strip byte array Pir8Radio 7 3,442 Nov-29-2022, 10:24 PM
Last Post: Pir8Radio
  Extract text rektcol 6 1,954 Jun-28-2022, 08:57 AM
Last Post: Gribouillis
  Extract a string between 2 words from a text file OscarBoots 2 1,996 Nov-02-2021, 08:50 AM
Last Post: ibreeden
  Extract text based on postion and pattern guddu_12 2 1,772 Sep-27-2021, 08:32 PM
Last Post: guddu_12
  Extract specific sentences from text file Bubly 3 3,646 May-31-2021, 06:55 PM
Last Post: Larz60+
  extract color text from PDF Maha 0 2,165 May-31-2021, 04:05 PM
Last Post: Maha
Question How to extract multiple text from a string? chatguy 2 2,548 Feb-28-2021, 07:39 AM
Last Post: bowlofred
  How to extract a single word from a text file buttercup 7 3,965 Jul-22-2020, 04:45 AM
Last Post: bowlofred
  How to extract specific rows and columns from a text file with Python Farhan 0 3,513 Mar-25-2020, 09:18 PM
Last Post: Farhan
  Extract Strings From Text File - Out Put Results to Individual Files dj99 8 5,181 Jun-28-2018, 10:41 AM
Last Post: dj99

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020