0
import json

string = "'massage':'testing'"

json.loads(string)

But I get this error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data/data/com.termux/files/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/data/data/com.termux/files/usr/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/data/data/com.termux/files/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
1
  • it should be match the json format, you miss the brackets Commented Aug 19, 2022 at 13:27

2 Answers 2

1

That is not valid JSON. This works:

import json
string = '{"message": "testing"}'
print(json.loads(string))

Not sure what this has to do with converting lists to dictionaries though.

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

Comments

0

according to the document

If the data being deserialized is not a valid JSON document, a
JSONDecodeError will be raised.

you have 2 mistake

  1. you miss the brackets in your string
  2. JSON specification - RFC7159 states that a string begins and ends with quotation mark. That mean single quoute ' has no semantic meaning in JSON and is allowed only inside a string.

result:

import json
string = '{"massage":"testing"}'
json.loads(string)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.