0

This is my first question here, so I thank everyone in advance for your patience...

I am trying to understand the solution with JSONDecoder for this question, and to learn at the same time how does raw_decode work.

From the documentation:

raw_decode(s)

Decode a JSON document from s (a str beginning with a JSON document) and return a 2-tuple of the Python representation and the index in s where the document ended.

This can be used to decode a JSON document from a string that may have extraneous data at the end.

I have a string beginning with a JSON document:

text = '{"param1":"1","param2":"2"} some other text'

And I'm trying to get from it a JSON document:

result, index = json.JSONDecoder.raw_decode(text)

Get

TypeError: raw_decode() missing 1 required positional argument: 's'

What am I missing? Where do I get it wrong? Thanks in advance for the answers!

Community
  • 1
  • 1
Georgy Goliev
  • 41
  • 1
  • 5
  • 1
    It's an *instance* method, not a class method. You need an instance before you can call that method. `d = JSONDecoder(); d.raw_decode(text)`. – deceze Feb 05 '20 at 16:12
  • @deceze thanks a lot for your instant answer! I understand that I lack basic python knowledge, but how can I understand from the documentation - is it instance or class method? – Georgy Goliev Feb 05 '20 at 16:33
  • 1
    Class methods are the exception, not the rule, in Python. Unless the docs explicitly say something is a class method, it's an instance method. – Charles Duffy Feb 05 '20 at 16:45

0 Answers0