0

I have following simple code,

import json
json1 = """
           ['Monday March 9', 'Tuesday March 3', 'Saturday March 7']
"""
x = json.loads(json1, encoding="utf-8")

I want to convert the json array string to be a list with json.loads, but the following error occurs:

  File "D:\JsonTest4.py", line 66, in test_3
    x = json.loads(json1, encoding="utf-8")
  File "d:\mypython\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "d:\mypython\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "d:\mypython\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 21 (char 21)

I would like to know where the problem is, thanks!

Tom
  • 5,848
  • 12
  • 44
  • 104
  • `ast.literal_eval(json1)` should work on this array. See [this](https://stackoverflow.com/questions/14347047/single-versus-double-quotes-in-json-loads-in-python). – ggorlen Jun 19 '20 at 05:56
  • Invalid json format I guess. – Amit kumar Jun 19 '20 at 05:59
  • https://jsonlint.com/?json=[%27Monday%20March%209%27,%20%27Tuesday%20March%203%27,%20%27Saturday%20March%207%27] suggests your JSON is using the wrong sort of quotes... – Anon Jun 19 '20 at 05:59

1 Answers1

2

It's not a valid json. Json strings must be double-quoted.

"""
           ["Monday March 9", "Tuesday March 3", "Saturday March 7"]
"""
Shashank V
  • 10,007
  • 2
  • 25
  • 41