Python: parsing JSON-like Javascript data structures (w/ consecutive commas)

前端 未结 6 1814
南旧
南旧 2020-12-10 22:55

I would like to parse JSON-like strings. Their lone difference with normal JSON is the presence of contiguous commas in arrays. When there are two such commas, it i

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-10 23:25

    Small & simple workaround to try out:

    1. Convert JSON-like data to strings.
    2. Replace ",," with ",null,".
    3. Convert it to whatever is your representation.
    4. Let JSONDecoder(), do the heavy lifting.

      1. & 3. can be omitted if you already deal with strings.

    (And if converting to string is impractical, update your question with this info!)

提交回复
热议问题