Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to read json file
#34
(Feb-25-2020, 04:11 PM)jk91 Wrote: "category” what should it be in a correct way then it might be deliberately so that it hould be a very complex case isn't it?
Sure it can have be placed there deliberately,so you shall clean it up.
You have given little info about the task,and all of this Thread is mostly been trying for you to open a working json file.

Alone it will be SyntaxError
>>> s = "category”
  File "<interactive input>", line 1
    s = "category”
                 ^
SyntaxError: EOL while scanning string literal
Reading it with json.load it will be JSONDecodeError.
So have to read file in a normal way so it's string output an clean it up before it's a working json file.
The cleaning up would be like this.
>>> s = '"category”'
>>> s
'"category”'
>>> s1 = s.replace('”', '"')
>>> s1
'"category"'
So if i mess up data.json with ,i would clean it up like this.
>>> with open('data.json', encoding='utf-8') as f:
...     file_content = f.read()

>>> fix = file_content.replace('”', '"')

>>> with open('fixed.json', 'w', encoding='utf-8') as f_out:
...     f_out.write(fix)
Reply


Messages In This Thread
how to read json file - by jk91 - Feb-18-2020, 11:48 AM
RE: how to read json file - by Larz60+ - Feb-18-2020, 06:02 PM
RE: how to read json file - by ndc85430 - Feb-18-2020, 06:10 PM
RE: how to read json file - by jk91 - Feb-19-2020, 05:44 AM
RE: how to read json file - by ndc85430 - Feb-19-2020, 06:41 AM
RE: how to read json file - by jk91 - Feb-19-2020, 07:28 AM
RE: how to read json file - by jk91 - Feb-20-2020, 06:17 AM
RE: how to read json file - by jk91 - Feb-20-2020, 09:18 AM
RE: how to read json file - by buran - Feb-20-2020, 09:40 AM
RE: how to read json file - by snippsat - Feb-20-2020, 10:03 AM
RE: how to read json file - by jk91 - Feb-20-2020, 11:20 AM
RE: how to read json file - by snippsat - Feb-20-2020, 12:07 PM
RE: how to read json file - by jk91 - Feb-20-2020, 02:10 PM
RE: how to read json file - by snippsat - Feb-20-2020, 02:38 PM
RE: how to read json file - by jk91 - Feb-23-2020, 06:37 AM
RE: how to read json file - by snippsat - Feb-23-2020, 10:49 AM
RE: how to read json file - by jk91 - Feb-23-2020, 11:03 AM
RE: how to read json file - by snippsat - Feb-23-2020, 12:06 PM
RE: how to read json file - by jk91 - Feb-23-2020, 01:17 PM
RE: how to read json file - by jk91 - Feb-23-2020, 02:24 PM
RE: how to read json file - by snippsat - Feb-23-2020, 03:30 PM
RE: how to read json file - by jk91 - Feb-23-2020, 04:26 PM
RE: how to read json file - by snippsat - Feb-23-2020, 04:50 PM
RE: how to read json file - by jk91 - Feb-24-2020, 11:56 AM
RE: how to read json file - by jk91 - Feb-24-2020, 01:15 PM
RE: how to read json file - by buran - Feb-24-2020, 01:28 PM
RE: how to read json file - by jk91 - Feb-24-2020, 01:38 PM
RE: how to read json file - by snippsat - Feb-24-2020, 01:45 PM
RE: how to read json file - by jk91 - Feb-24-2020, 06:22 PM
RE: how to read json file - by snippsat - Feb-24-2020, 07:45 PM
RE: how to read json file - by jk91 - Feb-25-2020, 04:11 PM
RE: how to read json file - by t4keheart - Feb-25-2020, 02:08 PM
RE: how to read json file - by t4keheart - Feb-25-2020, 06:24 PM
RE: how to read json file - by jk91 - Feb-26-2020, 08:10 AM
RE: how to read json file - by snippsat - Feb-26-2020, 05:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to read a file as binary or hex "string" so that I can do regex search? tatahuft 3 1,332 Dec-19-2024, 11:57 AM
Last Post: snippsat
  Read TXT file in Pandas and save to Parquet zinho 2 1,412 Sep-15-2024, 06:14 PM
Last Post: zinho
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 1,192 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  Pycharm can't read file Genericgamemaker 5 1,786 Jul-24-2024, 08:10 PM
Last Post: deanhystad
  Python is unable to read file Genericgamemaker 13 4,320 Jul-19-2024, 06:42 PM
Last Post: snippsat
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 3,508 May-03-2024, 07:23 AM
Last Post: Pedroski55
  encrypt data in json file help jacksfrustration 1 2,411 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  Recommended way to read/create PDF file? Winfried 3 5,406 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  parse json field from csv file lebossejames 4 2,176 Nov-14-2023, 11:34 PM
Last Post: snippsat
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 4,108 Nov-09-2023, 10:56 AM
Last Post: mg24

Forum Jump:

User Panel Messages

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