-1

I have the follow string, which I'm trying to load using python 2.7 json.loads.

{
    u'Status': {
        u'display_name': u'Status',
        u'is_updatable': True,
        u'type': u'TEXT',
        u'val': u'Paying',
        u'source': u'API'
    }, u'Create Date': {
        u'display_name': u'Create Date',
        u'is_updatable': True,
        u'type': u'DATE',
        u'val': u'2017-09-20',
        u'source': u'API'
    }, u'Total # of Projects': {
        u'display_name': u'Total # of Projects',
        u'is_updatable': True,
        u'type': u'TEXT',
        u'val': u'53',
        u'source': u'Pixel'
    }
 }

I'm getting the error:

ValueError: Expecting property name: line 1 column 2 (char 1)

Any ideas?

6
  • 3
    That's not valid JSON. JSON strings look like "this", not like u'this'. And booleans look like true, not like True. Commented Dec 26, 2017 at 14:59
  • That's not a json string. Json doesn't have u in front of strings since all strings are already unicode. Is that a python dict? Commented Dec 26, 2017 at 14:59
  • This is a string? You can't use a JSON parser, the u is not part of the standard JSON format. Commented Dec 26, 2017 at 14:59
  • 1
    import ast; ast.literal_eval(string) Commented Dec 26, 2017 at 14:59
  • 1
    Before you try to parse anything check that you don't have a python structure already because except of the formatting that is how it would be printed. Commented Dec 26, 2017 at 15:42

1 Answer 1

-1

Following file that you have pasted is not in json format. you can always check the validity of your JSON file using. https://jsoneditoronline.org/

OR

import json
a= {
    u'Status': {
        u'display_name': u'Status',
        u'is_updatable': True,
        u'type': u'TEXT',
        u'val': u'Paying',
        u'source': u'API'
    }, u'Create Date': {
        u'display_name': u'Create Date',
        u'is_updatable': True,
        u'type': u'DATE',
        u'val': u'2017-09-20',
        u'source': u'API'
    }, u'Total # of Projects': {
        u'display_name': u'Total # of Projects',
        u'is_updatable': True,
        u'type': u'TEXT',
        u'val': u'53',
        u'source': u'Pixel'
    }
 }
b=json.dumps(a) #String to json
print (b)
c=json.loads(b)
print (c)

Note :

json loads -> returns an object from a string representing a json object.

json dumps -> returns a string representing a json object from an object.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.