1

When I try to load following json in python:

"foo": {
            "foo_id": "1",
            "foo_name": "i",
            "foo_client_id": "2",
            "foo_client": "b",
        }

I got following error:

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

How do I parse this as a legal json?

3
  • 1) Wrap foo in another object ({}). 2) Remove trailing comma after b. Commented May 11, 2021 at 9:48
  • 1
    Does this answer your question? How to decode an invalid json string in python Commented May 11, 2021 at 9:50
  • What you have is not in valid JSON format — which doesn't allow that comma at the end of the last item (unlike Python). Commented May 11, 2021 at 10:06

1 Answer 1

0

This is not valid JSON due to the missing enclosing brackets and the trailing comma. However, it's valid YAML:

import yaml

data = '''
"foo": {
        "foo_id": "1",
        "foo_name": "i",
        "foo_client_id": "2",
        "foo_client": "b",
    }
'''
yaml.safe_load(data)  # returns a dict
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.