Json Valueerror: Expecting Property Name: Line 1 Column 2 (Char 1)

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

json.loads will load a json string into a python dict, json.dumps will dump a python dict to a json string, for example:

>>> json_string = '{"favorited": false, "contributors": null}'
'{"favorited": false, "contributors": null}'
>>> value = json.loads(json_string)
{u'favorited': False, u'contributors': None}
>>> json_dump = json.dumps(value)
'{"favorited": false, "contributors": null}'

So that line is incorrect since you are trying to load a python dict, and json.loads is expecting a valid json string which should have <type 'str'>.

So if you are trying to load the json, you should change what you are loading to look like the json_string above, or you should be dumping it. This is just my best guess from the given information. What is it that you are trying to accomplish?

Also you don't need to specify the u before your strings, as @Cld mentioned in the comments.

python json error Expecting property name: line 1 column 2 (char 1)

You data isn't a valid json which can be converted into dictionary, it's actually a dictinary, data shall be a valid json string, try to pass data below as a parameter:

data = '{"action": "tablestats", "userId": 3, "clientId": 3, "module": "report"}'

See more about json in the article "JSON: What It Is, How It Works, & How to Use It"

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

It looks like your "json" is actually python literal syntax. In that case, it might be easier to ast.literal_eval the string1.

As a side benefit, then you don't have to do any (possibly sketchy) replacements of None with "None". (Consider a tweet which says "None of your base are belong to us")

1although it would probably be even better to make sure that proper json is being dumped into the database to begin with...

Trying to parse JSON in Python. ValueError: Expecting property name

That's definitely not JSON - not as printed above anyhow. It's already been parsed into a Python object - JSON would have false, not False, and wouldn't show strings as u for unicode (all JSON strings are unicode). Are you sure you're not getting your json string turned into a Python object for free somewhere in the chain already, and thus loading it into json.loads() is obviously wrong because in fact it's not a string?

pythoin and json - ValueError: Expecting property name: line 1 column 1 (char 1)

Wait, are you converting a python dict into json? In that case use json.dumps. The args as you have defined on first line is in fact a dict.

args = {'series': 'exr|usd|gbp', 'K': 2, 'M': 2, 'tau': 1}
print args.__class__
Out: dict
args = json.dumps(args)
print args
Out: '{"series": "exr|usd|gbp", "K": 2, "M": 2, "tau": 1}'

In json parsable string as expected.

Python/Json:Expecting property name enclosed in double quotes

This:

{
'http://example.org/about': {
'http://purl.org/dc/terms/title': [
{'type': 'literal', 'value': "Anna's Homepage"}
]
}
}

is not JSON.

This:

{
"http://example.org/about": {
"http://purl.org/dc/terms/title": [
{"type": "literal", "value": "Anna's Homepage"}
]
}
}

is JSON.

EDIT:

Some commenters suggested that the above is not enough.

JSON specification - RFC7159 states that a string begins and ends with quotation mark. That is ".

Single quoute ' has no semantic meaning in JSON and is allowed only inside a string.

python, json.loads Expecting property name: line 1 column 2 (char 2)

That's not JSON. While you go and figure out why it's not outputting JSON, you can use ast.literal_eval().

>>> ast.literal_eval('''[{u'body': u'this is the message body', u'user_id': u'8', u'name': u'Mark', u'time': u'2013-10-10-16:32'}]''')
[{u'body': u'this is the message body', u'user_id': u'8', u'name': u'Mark', u'time': u'2013-10-10-16:32'}]


Related Topics



Leave a reply



Submit