[Python] How do I automatically fix an invalid JSON string?

Discussão em 'Python' iniciado por Stack, Dezembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    From the 2gis API I got the following JSON string.

    {
    "api_version": "1.3",
    "response_code": "200",
    "id": "3237490513229753",
    "lon": "38.969916127827",
    "lat": "45.069889625267",
    "page_url": null,
    "name": "ATB",
    "firm_group": {
    "id": "3237499103085728",
    "count": "1"
    },
    "city_name": "Krasnodar",
    "city_id": "3237585002430511",
    "address": "Turgeneva, 172/1",
    "create_time": "2008-07-22 10:02:04 07",
    "modification_time": "2013-08-09 20:04:36 07",
    "see_also": [
    {
    "id": "3237491513434577",
    "lon": 38.973110606808,
    "lat": 45.029031222211,
    "name": "Advance",
    "hash": "5698hn745A8IJ1H86177uvgn94521J3464he26763737242Cf6e654G62J0I7878e",
    "ads": {
    "sponsored_article": {
    "title": "Center "ADVANCE"",
    "text": "Business.English."
    },
    "warning": null
    }
    }
    ]
    }


    But Python doesn't recognize it:

    json.loads(firm_str)


    Expecting , delimiter: line 1 column 3646 (char 3645)
    ​

    It looks like a problem with quotes in: "title": "Center "ADVANCE""

    How can I fix it automatically in Python?

    Continue reading...

Compartilhe esta Página