Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JSON Decoder issue
#1
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)
Reply
#2
Quote:
buffer = str(my_bittrex.get_ticker("USDT-BTC")).replace("'",'"')
         ^^^

What type is it before you turn it into a string?
Reply
#3
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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can i fix json.decoder.JSONDecodeError ? JgKSuperstar 9 4,632 Oct-30-2021, 11:23 PM
Last Post: JgKSuperstar
  coding a decoder... Popkhorn 2 2,115 May-28-2020, 07:26 AM
Last Post: Popkhorn
  reset on inactivity (building a morse decoder) gerrit1985 7 3,554 Apr-17-2020, 10:22 AM
Last Post: deanhystad
  Issue with a script to convert xls to json Will86 2 3,828 Dec-19-2018, 08:23 AM
Last Post: Will86
  UTF-8 decoder reports bad byte that is not there Skaperen 0 2,300 Oct-11-2018, 04:46 AM
Last Post: Skaperen
  MP4 decoder jdewk 4 5,589 Jan-13-2018, 10:02 PM
Last Post: jdewk

Forum Jump:

User Panel Messages

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