Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
can't parse json file
#1
I have below code:
import os
import datetime
import json


def prt_list(vdata, vtype,vcol):
   print("Here is listing of {}:".format(vtype))
   for item in vdata:
     print (item[vcol])
 

wk_dir = '1139'
file_name = 'cust.json'

v_path=os.path.join('c:\\dell',wk_dir)
v_file=os.path.join('c:\\dell',wk_dir,file_name)

v_files=os.listdir(v_path)
for f in v_files:
  print(f)
print("\n")
m_file=open(v_file,'r')

m_data=json.load(m_file)
print(m_data)

prt_list(m_data,'customers','name')

m_file.close()
json file cust.json below:
Output:
[ { "id":1, "name": "jame" "email": "[email protected]" }, { "id":2, "name": "Apple" "email": "[email protected]" } ]
I get error :
Error:
Traceback (most recent call last): File "C:\dell\testio_json.py", line 24, in <module> m_data=json.load(m_file) File "C:\dell\pythonwin\lib\json\__init__.py", line 268, in load parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) File "C:\dell\pythonwin\lib\json\__init__.py", line 319, in loads return _default_decoder.decode(s) File "C:\dell\pythonwin\lib\json\decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\dell\pythonwin\lib\json\decoder.py", line 355, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting ',' delimiter: line 5 column 2 (char 31)
any idea? thanks
Reply
#2
looking at your json file (without testing), it appears that you are missing commas:
Output:
[ { "id":1, "name": "jame", "email": "[email protected]" }, { "id":2, "name": "Apple", "email": "[email protected]" } ]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 74 Yesterday, 05:16 PM
Last Post: deanhystad
  parse json field from csv file lebossejames 4 669 Nov-14-2023, 11:34 PM
Last Post: snippsat
  parse/read from file seperated by dots giovanne 5 1,044 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Python Script to convert Json to CSV file chvsnarayana 8 2,347 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Loop through json file and reset values [SOLVED] AlphaInc 2 1,962 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  [split] Parse Nested JSON String in Python mmm07 4 1,429 Mar-28-2023, 06:07 PM
Last Post: snippsat
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,179 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  validate large json file with millions of records in batches herobpv 3 1,223 Dec-10-2022, 10:36 PM
Last Post: bowlofred
  Writing to json file ebolisa 1 970 Jul-17-2022, 04:51 PM
Last Post: deanhystad
  Trying to parse only 3 key values from json file cubangt 8 3,339 Jul-16-2022, 02:05 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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