Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with reading json file
Can anyone help me to review this short code below that read json data from url?
I am not sure why it give error.
Thank you,

data = pd.read_json('')
what was the error, please show unmodified and complete error traceback (bound by bbcode tags)
The whole traceback is:
Traceback (most recent call last): File "<input>", line 1, in <module> File "D:\Python\Homework\venv\lib\site-packages\pandas\util\", line 199, in wrapper return func(*args, **kwargs) File "D:\Python\Homework\venv\lib\site-packages\pandas\util\", line 299, in wrapper return func(*args, **kwargs) File "D:\Python\Homework\venv\lib\site-packages\pandas\io\json\", line 563, in read_json return File "D:\Python\Homework\venv\lib\site-packages\pandas\io\json\", line 694, in read obj = self._get_object_parser( File "D:\Python\Homework\venv\lib\site-packages\pandas\io\json\", line 716, in _get_object_parser obj = FrameParser(json, **kwargs).parse() File "D:\Python\Homework\venv\lib\site-packages\pandas\io\json\", line 831, in parse self._parse_no_numpy() File "D:\Python\Homework\venv\lib\site-packages\pandas\io\json\", line 1078, in _parse_no_numpy self.obj = DataFrame( File "D:\Python\Homework\venv\lib\site-packages\pandas\core\", line 529, in __init__ mgr = init_dict(data, index, columns, dtype=dtype) File "D:\Python\Homework\venv\lib\site-packages\pandas\core\internals\", line 287, in init_dict return arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype) File "D:\Python\Homework\venv\lib\site-packages\pandas\core\internals\", line 80, in arrays_to_mgr index = extract_index(arrays) File "D:\Python\Homework\venv\lib\site-packages\pandas\core\internals\", line 404, in extract_index raise ValueError( ValueError: Mixing dicts with non-Series may lead to ambiguous ordering.
buran write Jul-07-2021, 07:06 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Exactly what datafarme would you expect to produce from this JSON? It doesn't look suitable for processing as dataframe

Why not simply read the JSON and then process it?

import requests

response = requests.get('')
data = response.json()

print(f"Total Gross: {data['totalGross']['currency']} {data['totalGross']['value']}")
{'resourceType': 'Invoice', 'id': 'example', 'text': {'status': 'generated', 'div': '<div xmlns="">Example of Invoice</div>'}, 'identifier': [{'system': '', 'value': '654321'}], 'status': 'issued', 'subject': {'reference': 'Patient/example'}, 'date': '2017-01-25T08:00:00+01:00', 'participant': [{'role': {'coding': [{'system': '', 'code': '17561000', 'display': 'Cardiologist'}]}, 'actor': {'reference': 'Practitioner/example'}}], 'issuer': {'identifier': {'system': 'http://myhospital/NamingSystem/departments', 'value': 'CARD_INTERMEDIATE_CARE'}}, 'account': {'reference': 'Account/example'}, 'totalNet': {'value': 40, 'currency': 'EUR'}, 'totalGross': {'value': 48, 'currency': 'EUR'}} Total Gross: EUR 48
hhchenfx and Larz60+ like this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

To read it do.
data = pd.read_json('', orient='index')
Quick test NoteBook
I just mess around a transpose,the way to go is look at Pandas json_normalize(),as in post under.
How to parse JSON data with Python Pandas?
hhchenfx likes this post
Thank you all for helping.
I understand it now.

Possibly Related Threads…
Thread Author Replies Views Last Post
Question In need of insight regarding Python file reading mechanisms. EnfantNicolas 7 199 Sep-18-2021, 10:39 AM
Last Post: ndc85430
  [Solved] Reading every nth line into a column from txt file Laplace12 7 770 Jun-29-2021, 09:17 AM
Last Post: Laplace12
  help with project of reading and searching big log file korenron 6 388 Jun-24-2021, 01:57 PM
Last Post: korenron
  Helps with reading csv file - 3 methods hhchenfx 4 664 May-13-2021, 04:15 AM
Last Post: buran
  Subprocess.Popen() not working when reading file path from csv file herwin 13 1,696 May-07-2021, 03:26 PM
Last Post: herwin
  Request for Python code - Features extraction from JSON file (cuckoo) thinker 1 557 Apr-07-2021, 04:40 PM
Last Post: Larz60+
  find the header location in a .bin file without reading the whole file at a time SANJIB 0 569 Mar-05-2021, 04:08 PM
Last Post: SANJIB
  Reading a csv file Led_Zeppelin 2 786 Feb-26-2021, 05:48 AM
Last Post: buran
  reading a csv file Led_Zeppelin 3 986 Feb-19-2021, 02:16 PM
Last Post: Led_Zeppelin
  Sort data from JSON file Dummy_in_programming 2 671 Jan-04-2021, 06:17 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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