Python Forum
JSON Decoder issue - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: JSON Decoder issue (/thread-4919.html)



JSON Decoder issue - Cronax3 - Sep-13-2017

Hey community,
currently I am programming a programing which is using the python Bittrex-API wrapper.
I ran into a problem which I am not able to resolve at the moment so I am asking for some help.
I am receiving a current market json file and a pretty confusing error. As you can see having a look at
the ouput I first print out the receiving data from the API wrapper but JSON is complaingin as you can see at
the bottom. I dunno how to fix this :(

Sourcecode:
from bittrex import Bittrex
import json

 
my_bittrex = Bittrex(None, None)
buffer = str(my_bittrex.get_ticker("USDT-BTC")).replace("'",'"')
print(buffer)
parsed_json = json.loads(buffer)
print(parsed_json["Last"])
Just in case you are wondering about the replace function: I used it because the API wrapper returns a json string using single quotes and JSON complained about it. It said I have to use double quotes so I replaced them.
Output:
Output:
{"result": {"Last": 4159.99999999, "Ask": 4159.99999999, "Bid": 4133.0}, "success": True, "message": ""} Traceback (most recent call last): File "/home/pi/C9Workspace/Python/bittrex_test.py", line 8, in <module> parsed_json = json.loads(buffer) File "/usr/lib/python3.5/json/__init__.py", line 319, in loads return _default_decoder.decode(s) File "/usr/lib/python3.5/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 85 (char 84)



RE: JSON Decoder issue - nilamo - Sep-13-2017

Quote:
buffer = str(my_bittrex.get_ticker("USDT-BTC")).replace("'",'"')
         ^^^

What type is it before you turn it into a string?


RE: JSON Decoder issue - Cronax3 - Sep-13-2017

The Datatype is 'dict'.
Ok as I realize now I don't need to tread it as a json. Its not meant to be json at all and thats why the decoder is complaining. I misunderstood the api documentation. I completely messed this point up. Didn't even realize its a dict. My problem is solved now. Thanks for the hint!