0

Assume there is a string like '{"a": None}'. How to let Python know the existence of None?

This is the error I have been receiving:

JSONDecodeError: Expecting value: line 1 column 7 (char 6)
Memphis Meng
  • 1,267
  • 2
  • 13
  • 34
  • Does this answer your question? [Convert a String representation of a Dictionary to a dictionary?](https://stackoverflow.com/questions/988228/convert-a-string-representation-of-a-dictionary-to-a-dictionary) – Iain Shelvington Jun 08 '22 at 17:18
  • 3
    If you are trying to decode a JSON, which is implied by your error, you should use `null` instead of `None`. – mati.o Jun 08 '22 at 17:18

1 Answers1

0

I'm not sure what you mean exactly by "letting python know of the existence of None," but you can easily convert the string to a dictionary by using the eval function like so:

json_entry = eval('{"a": None}')
print(json_entry["a"])

Output:

 None
PurpleHacker
  • 358
  • 2
  • 9