How to decode an invalid json string in python

后端 未结 4 1439
自闭症患者
自闭症患者 2020-12-18 03:57

I wonder if there is a way to decode a JSON-like string.

I got string:

\'{ hotel: { id: \"123\", name: \"hotel_name\"} }\'

It\'s no

4条回答
  •  抹茶落季
    2020-12-18 05:01

    @vartec has already pointed out demjson, which works well for slightly invalid JSON. For data that's even less JSON compliant I've written barely_json:

    from barely_json import parse
    print(parse('[no, , {complete: yes, where is my value?}]'))
    

    prints

    [False, '', {'complete': True, 'where is my value?': ''}]
    

提交回复
热议问题