Feb-01-2017, 06:08 AM
Hello:
I'm new to Python. I'm using 3.5.3 on Windows.
Got a bit of a struggle with JSON where the data has no braces {} and only has brackets []. I'm unable to post the link (new to the forum, not a proven non-spammer). The data is from the US Census. The goal is to dump the extract onto a local text file. There are many of files I need to pull, so saving CSVs is not really an option.
Here is a sample of the data
[
Based on the standard, it seems this is OK, if the data has no key.
The Python syntax below "bombs" when I assign it to the S variable using method "dump" for a string, so "dumps"
>>> import requests
>>>
>>> response = requests.get("....census api call goes here with key....")
>>> import json
# bombs on this line below, everything above is OK
>>> s=json.dumps(response)
basically this comes back as is not JSON serializable ... from the standards, I understand why this is happening. I can't find a solution that will "serialize it."
Any thoughts would be appreciated.
Thank you
Mariusz
I'm new to Python. I'm using 3.5.3 on Windows.
Got a bit of a struggle with JSON where the data has no braces {} and only has brackets []. I'm unable to post the link (new to the forum, not a proven non-spammer). The data is from the US Census. The goal is to dump the extract onto a local text file. There are many of files I need to pull, so saving CSVs is not really an option.
Here is a sample of the data
[
- [
- "BIRTHS",
- "YEAR",
- "us"
- "BIRTHS",
],
[- "3969976",
- "2014",
- "1"
- "3969976",
],
[- "3998730",
- "2015",
- "1"
- "3998730",
],
Based on the standard, it seems this is OK, if the data has no key.
The Python syntax below "bombs" when I assign it to the S variable using method "dump" for a string, so "dumps"
>>> import requests
>>>
>>> response = requests.get("....census api call goes here with key....")
>>> import json
# bombs on this line below, everything above is OK
>>> s=json.dumps(response)
basically this comes back as is not JSON serializable ... from the standards, I understand why this is happening. I can't find a solution that will "serialize it."
Any thoughts would be appreciated.
Thank you
Mariusz