1

I have the following simple json in a file saved as notepad file t.json

[{"a": 1, "b": 2, "c": 3},
{"a": 4, "b": 5, "c": 6},
{"a": 7, "b": 8, "c": 9}]

I am trying to open it using

ValueError                                Traceback (most recent call last)
<ipython-input-236-487720f2328b> in <module>()
----> 1 data = pd.read_json('t.json')

~\Anaconda3\lib\site-packages\pandas\io\json\json.py in read_json(path_or_buf, orient, typ, dtype, convert_axes, convert_dates, keep_default_dates, numpy, precise_float, date_unit, encoding, lines, chunksize, compression)
    420         return json_reader
    421
--> 422     result = json_reader.read()
    423     if should_close:
    424         try:

~\Anaconda3\lib\site-packages\pandas\io\json\json.py in read(self)
    527             )
    528         else:
--> 529             obj = self._get_object_parser(self.data)
    530         self.close()
    531         return obj

~\Anaconda3\lib\site-packages\pandas\io\json\json.py in _get_object_parser(self, json)
    544         obj = None
    545         if typ == 'frame':
--> 546             obj = FrameParser(json, **kwargs).parse()
    547
    548         if typ == 'series' or obj is None:

~\Anaconda3\lib\site-packages\pandas\io\json\json.py in parse(self)
    636
    637         else:
--> 638             self._parse_no_numpy()
    639
    640         if self.obj is None:

~\Anaconda3\lib\site-packages\pandas\io\json\json.py in _parse_no_numpy(self)
    851         if orient == "columns":
    852             self.obj = DataFrame(
--> 853                 loads(json, precise_float=self.precise_float), dtype=None)
    854         elif orient == "split":
    855             decoded = {str(k): v for k, v in compat.iteritems(

ValueError: Expected object or value

I have tried creating an absolute path as per the suggestion in this page but it also produces a value error. Can anyone help please?

1

1 Answer 1

2

There is a possibility this is a bug of pandas module. What version are you using? Consider updating.

After that you can try the following:

data  = pd.read_json('t.json', lines=False)

Hope it helps

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the suggestion. Strangely when I run 'conda update panda' i get an error ''conda' is not recognized as an internal or external command, operable program or batch file' Does this suggest an update of anaconda needed?
I think that windows cannot find the conda tool. You have to specify the path. Check stackoverflow.com/questions/44597662/…. However, consider installing pandas using pip (stackoverflow.com/questions/4750806/…)
Also using the parameter lines=False does solve the problem?
I've updated conda. created a an asbolute path as follows path = os.path.abspath("DESKTOP\python work jan") and then ran this data = pd.read_json(path + '\t.json', lines=False) to get an error read_json() got an unexpected keyword argument 'path'
Could you move the t.json file to your working folder, or specify the path directly in read_json without using the os,path module? if you need to specify the absolute path, consider using desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop') to get the path to your Desktop and path.join in general to avoid mistakes when merging paths.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.