0

I have a set of following data :

{
    "dataFrame": "AB3hqqqpVVVOAAA=", 
    "decrypted": true, 
    "fcnt": 3, 
    "id": 1480528200533, 
    "port": 5, 
    "rssi": -116, 
    "sf_used": 10, 
    "snr": -8.5, 
    "timestamp": "2016-11-30T17:50:00.533Z"
}, 

{
    "dataFrame": "AB3hqqqpVVVOAAA=", 
    "decrypted": true, 
    "fcnt": 5, 
    "id": 1480528235613, 
    "port": 5, 
    "rssi": -119, 
    "sf_used": 10, 
    "snr": -5.8, 
    "timestamp": "2016-11-30T17:50:35.613Z"
}, 
{
    "dataFrame": "AB7hqqqpVVVOAAA=", 
    "decrypted": true, 
    "fcnt": 7, 
    "id": 1480528310609, 
    "port": 5, 
    "rssi": -120, 
    "sf_used": 10, 
    "snr": -8.8, 
    "timestamp": "2016-11-30T17:51:50.609Z"
}, 
{
    "dataFrame": "AB7hqqqpVVVOAAA=", 
    "decrypted": true, 
    "fcnt": 9, 
    "id": 1480528403504, 
    "port": 5, 
    "rssi": -116, 
    "sf_used": 10, 
    "snr": -9.2, 
    "timestamp": "2016-11-30T17:53:23.504Z"
}, 

I am trying to convert above into dictionary type :

{
    u'dataFrame': 'AB3hqqqpVVVOAAA=', 
    u'decrypted': true, 
    u'fcnt': 3, 
    u'id': 1480528200533, 
    u'port': 5, 
    u'rssi': -116, 
    u'sf_used': 10, 
    u'snr': -8.5, 
    u'timestamp': '2016-11-30T17:50:00.533Z'
}

So when I try to use infile = json.load(infile) where infile is my input file, why am i getting error like ValueError : extra data ?

1 Answer 1

1

Because your input file is a number of json objects in a row, not a list of json objects. The parser will see the first , after the first object closes, and have no idea why that comma is there, so it raises a ValueError (which is actually a json syntax error).

Make the objects into a list by adding a single [ ] around them all like so:

[{
    "dataFrame": "AB3hqqqpVVVOAAA=", 
    "decrypted": true, 
    "fcnt": 3, 
    "id": 1480528200533, 
    "port": 5, 
    "rssi": -116, 
    "sf_used": 10, 
    "snr": -8.5, 
    "timestamp": "2016-11-30T17:50:00.533Z"
}, 

{
    "dataFrame": "AB3hqqqpVVVOAAA=", 
    "decrypted": true, 
    "fcnt": 5, 
    "id": 1480528235613, 
    "port": 5, 
    "rssi": -119, 
    "sf_used": 10, 
    "snr": -5.8, 
    "timestamp": "2016-11-30T17:50:35.613Z"
}, 
{
    "dataFrame": "AB7hqqqpVVVOAAA=", 
    "decrypted": true, 
    "fcnt": 7, 
    "id": 1480528310609, 
    "port": 5, 
    "rssi": -120, 
    "sf_used": 10, 
    "snr": -8.8, 
    "timestamp": "2016-11-30T17:51:50.609Z"
}, 
{
    "dataFrame": "AB7hqqqpVVVOAAA=", 
    "decrypted": true, 
    "fcnt": 9, 
    "id": 1480528403504, 
    "port": 5, 
    "rssi": -116, 
    "sf_used": 10, 
    "snr": -9.2, 
    "timestamp": "2016-11-30T17:53:23.504Z"
}]
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.