-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?

cs95
  • 379,657
  • 97
  • 704
  • 746
  • 3
    That's not valid JSON. JSON strings look like `"this"`, not like `u'this'`. And booleans look like `true`, not like `True`. – khelwood Dec 26 '17 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? – solarc Dec 26 '17 at 14:59
  • This is a string? You can't use a JSON parser, the `u` is not part of the standard JSON format. – cs95 Dec 26 '17 at 14:59
  • 1
    `import ast; ast.literal_eval(string)` – cs95 Dec 26 '17 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. – Klaus D. Dec 26 '17 at 15:42
  • Not the first person to try to parse Python `repr()` output as if it were JSON -- we *do* have a duplicate for this. – Charles Duffy Dec 26 '17 at 17:05

1 Answers1

0

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.

vanishka
  • 167
  • 2
  • 12