VBA Json Parse response with JsonConverter - json

Posting request API to Statistics Canada.
The Response string I'm getting is complex (at least to me) and I can not extract any value from it.
Tried many syntax possible to only get the "cansimId" without success.
My goal would be to list (array loop) the "dimensionPositionId":2 ("Principal statistics") and get all ("memberNameEn")
Many thanks! :)
Here's a sample from the response. Too big to post it all here +100K.txt:
[
{
"status": "SUCCESS",
"object": {
"responseStatusCode": 0,
"productId": "16100047",
"cansimId": "304-0014",
"cubeTitleEn": "Manufacturers' sales, inventories, orders and inventory to sales ratios, by industry (dollars unless otherwise noted)",
"cubeTitleFr": "Stocks, ventes, commandes et rapport des stocks sur les ventes pour les industries manufacturières, selon l'industrie (dollars sauf indication contraire)",
"cubeStartDate": "1992-01-01",
"cubeEndDate": "2021-08-01",
"frequencyCode": 6,
"nbSeriesCube": 2798,
"nbDatapointsCube": 935808,
"releaseTime": "2021-10-14T08:30",
"archiveStatusCode": "2",
"archiveStatusEn": "CURRENT - a cube available to the public and that is current",
"archiveStatusFr": "ACTIF - un cube qui est disponible au public et qui est toujours mise a jour",
"subjectCode": [
"1699",
"230402",
"330303",
"451003"
],
"surveyCode": [
"2101"
],
"dimension": [
{
"dimensionPositionId": 1,
"dimensionNameEn": "Geography",
"dimensionNameFr": "Géographie",
"hasUom": false,
"member": [
{
"memberId": 1,
"parentMemberId": null,
"memberNameEn": "Canada",
"memberNameFr": "Canada",
"classificationCode": "11124",
"classificationTypeCode": "1",
"geoLevel": 0,
"vintage": 2016,
"terminated": 0,
"memberUomCode": null
}
]
},
{
"dimensionPositionId": 2,
"dimensionNameEn": "Principal statistics",
"dimensionNameFr": "Les statistiques principales",
"hasUom": true,
"member": [
{
"memberId": 1,
"parentMemberId": null,
"memberNameEn": "Sales of goods manufactured (shipments)",
"memberNameFr": "Ventes de biens fabriqués (livraisons)",
"classificationCode": null,
"classificationTypeCode": null,
"geoLevel": null,
"vintage": null,
"terminated": 0,
"memberUomCode": 81
},
{
"memberId": 2,
"parentMemberId": null,
"memberNameEn": "New orders, estimated values of orders received during month",
"memberNameFr": "Nouvelles commandes, valeur estimative des commandes reçues durant le mois",
"classificationCode": null,
"classificationTypeCode": null,
"geoLevel": null,
"vintage": null,
"terminated": 0,
"memberUomCode": 81
},
{
"memberId": 3,
"parentMemberId": null,
"memberNameEn": "Unfilled orders, estimated values of orders at end of month",
"memberNameFr": "Commandes en carnet, valeur estimative des commandes à la fin du mois",
"classificationCode": null,
"classificationTypeCode": null,
"geoLevel": null,
"vintage": null,
"terminated": 0,
"memberUomCode": 81
},
{
"memberId": 4,
"parentMemberId": null,
"memberNameEn": "Raw materials, fuel, supplies, components, estimated values at end of month",
"memberNameFr": "Matières premières, combustibles, fournitures et composantes, valeur estimative à la fin du mois",
"classificationCode": null,
"classificationTypeCode": null,
"geoLevel": null,
"vintage": null,
"terminated": 0,
"memberUomCode": 81
},
{
"memberId": 5,
"parentMemberId": null,
"memberNameEn": "Goods or work in process, estimated values at end of month",
"memberNameFr": "Biens en cours de fabrication ou travaux en cours, valeur estimative à la fin du mois",
"classificationCode": null,
"classificationTypeCode": null,
"geoLevel": null,
"vintage": null,
"terminated": 0,
"memberUomCode": 81
},
{
"memberId": 6,
"parentMemberId": null,
"memberNameEn": "Finished goods manufactured, estimated values at end of month",
"memberNameFr": "Produits finis fabriqués, valeur estimative à la fin du mois",
"classificationCode": null,
"classificationTypeCode": null,
"geoLevel": null,
"vintage": null,
"terminated": 0,
"memberUomCode": 81
},
{
"memberId": 7,
"parentMemberId": null,
"memberNameEn": "Total inventory, estimated values of total inventory at end of the month",
"memberNameFr": "Total des stocks, valeur estimative des stocks à la fin du mois",
"classificationCode": null,
"classificationTypeCode": null,
"geoLevel": null,
"vintage": null,
"terminated": 0,
"memberUomCode": 81
},
{
"memberId": 8,
"parentMemberId": null,
"memberNameEn": "Ratio of total inventory to sales",
"memberNameFr": "Rapport du total des stocks aux ventes",
"classificationCode": null,
"classificationTypeCode": null,
"geoLevel": null,
"vintage": null,
"terminated": 0,
"memberUomCode": 270
},
{
"memberId": 9,
"parentMemberId": null,
"memberNameEn": "Ratio of finished goods to sales",
"memberNameFr": "Rapport des produits finis aux ventes",
"classificationCode": null,
"classificationTypeCode": null,
"geoLevel": null,
"vintage": null,
"terminated": 0,
"memberUomCode": 270
}
]
},
And here's the code:
Dim Request As New MSXML2.XMLHTTP60
Dim Body As String
Dim Json As Object
Body = "[{" & Chr(34) & "productId" & Chr(34) & ":16100047}]"
Request.Open "POST", "https://www150.statcan.gc.ca/t1/wds/rest/getCubeMetadata", False
Request.SetRequestHeader "Content-Type", "application/json"
Request.send Body
Set Json = JsonConverter.ParseJson(Request.ResponseText)
'Debug.print Json("status") 'Error !!!!
'Debug.Print Json("cansimId") 'Error!!!!
'Debug.print Json("object")("cansimId") 'Error!!!!

Thank's Tomalak, you were right!
One thing... All my arrays seems to be 'option base 1' (although not specify!)
So Json(1)("status") is now working.
Finaly got what I needed:
Dim ColStatPrinc As Collection
Dim StatPrinc As Dictionary
x = 1
Set ColStatPrinc = Json(1)("object")("dimension")(2)("member")
With Sheets(1)
For Each StatPrinc In ColStatPrinc
.Cells(x, 1) = StatPrinc("memberId")
.Cells(x, 2) = StatPrinc("memberNameFr")
x = x + 1
Next StatPrinc
End With

Related

Parse the following JSON using google apps script

-- Hi everyone, It's been now several days I'm trying to parse the following JSON using google apps script.
[
{
"NOMBRE": "ViejosNoUsarEl Quebrachal",
"ACTIVO": false,
"CODIGO": "ViejosNoUsarQUEB",
"CALLE": null,
"NUMERO": null,
"PROVINCIA": "Jujuy",
"LOCALIDAD": "EL MORRO",
"ZONA": null,
"SUPERFICIE": 3900,
"CODIGOEXTERNO": ""
},
{
"NOMBRE": "ViejoNoUsarSanta Teresa",
"ACTIVO": false,
"CODIGO": "ViejoNoUsarST",
"CALLE": null,
"NUMERO": null,
"PROVINCIA": "San Luis",
"LOCALIDAD": "Villa MercedesOLD",
"ZONA": "Oeste",
"SUPERFICIE": 3700,
"CODIGOEXTERNO": ""
},
{
"NOMBRE": "ViejosNoUsarGil",
"ACTIVO": false,
"CODIGO": "ViejosNoUsarGIL",
"CALLE": null,
"NUMERO": null,
"PROVINCIA": "Cordoba",
"LOCALIDAD": "9 DE JULIO",
"ZONA": "Oeste",
"SUPERFICIE": 200,
"CODIGOEXTERNO": ""
},
{
"NOMBRE": "ViejosNoUsarDon Manuel",
"ACTIVO": false,
"CODIGO": "ViejosNoUsarDM",
"CALLE": null,
"NUMERO": null,
"PROVINCIA": "Cordoba",
"LOCALIDAD": "9 DE JULIO",
"ZONA": "Oeste",
"SUPERFICIE": 400,
"CODIGOEXTERNO": ""
}
]
The GET response is giving me the JSON as I posted it.
Using google apps script I want to add on a google sheet as much rows as objects are in the array.
In this case there would be 4 google sheet rows. I want to parse only the values of the properties.
As an example, the first row would look like this:
ViejosNoUsarEl Quebrachal | false | ViejosNoUsarQUEB | null | null | Jujuy | EL MORRO | null | 3900 |
I want to focus on this question on the pasrsing matter, not on the adding the rows to the google sheet yet.
The problem is that I cant get the dot notation to extract the values I want.
For example, Logger.log(response.provincia); prints "Information null".
Modification points:
From your showing sample data and For example, Logger.log(response.provincia); prints "Information null"., I thought that the reason for your issue is due to that you are trying to retrieve the values from an array using response.provincia. In this case, it is required to be response[i].PROVINCIA. i is the index of an array. If you want to retrieve the value of "PROVINCIA" of the 1st element of the array, you can use response[0].PROVINCIA. From your showing data, provincia is required to be PROVINCIA. When response[0].provincia is run, undefined is returned. Please be careful about this.
When you want to retrieve the values like ViejosNoUsarEl Quebrachal | false | ViejosNoUsarQUEB | null | null | Jujuy | EL MORRO | null | 3900 | in order, in this case, the values are retrieved by preparing the keys in order.
When these points are reflected in a sample script, it becomes as follows.
Sample script:
const keys = ["NOMBRE", "ACTIVO", "CODIGO", "CALLE", "NUMERO", "PROVINCIA", "LOCALIDAD", "ZONA", "SUPERFICIE", "CODIGOEXTERNO"];
const response = [
{
"NOMBRE": "ViejosNoUsarEl Quebrachal",
"ACTIVO": false,
"CODIGO": "ViejosNoUsarQUEB",
"CALLE": null,
"NUMERO": null,
"PROVINCIA": "Jujuy",
"LOCALIDAD": "EL MORRO",
"ZONA": null,
"SUPERFICIE": 3900,
"CODIGOEXTERNO": ""
},
{
"NOMBRE": "ViejoNoUsarSanta Teresa",
"ACTIVO": false,
"CODIGO": "ViejoNoUsarST",
"CALLE": null,
"NUMERO": null,
"PROVINCIA": "San Luis",
"LOCALIDAD": "Villa MercedesOLD",
"ZONA": "Oeste",
"SUPERFICIE": 3700,
"CODIGOEXTERNO": ""
},
{
"NOMBRE": "ViejosNoUsarGil",
"ACTIVO": false,
"CODIGO": "ViejosNoUsarGIL",
"CALLE": null,
"NUMERO": null,
"PROVINCIA": "Cordoba",
"LOCALIDAD": "9 DE JULIO",
"ZONA": "Oeste",
"SUPERFICIE": 200,
"CODIGOEXTERNO": ""
},
{
"NOMBRE": "ViejosNoUsarDon Manuel",
"ACTIVO": false,
"CODIGO": "ViejosNoUsarDM",
"CALLE": null,
"NUMERO": null,
"PROVINCIA": "Cordoba",
"LOCALIDAD": "9 DE JULIO",
"ZONA": "Oeste",
"SUPERFICIE": 400,
"CODIGOEXTERNO": ""
}
];
const values = response.map(o => keys.map(h => o[h]));
console.log(values)
When this script is run, the values are returned as the 2-dimensional array. This can be used for putting to the Spreadsheet using setValues.
Reference:
map()

Parsing JSON without key names to retrieve a column

I am loading json from data.gov that does not have key names for the values in the json data, e.g. below: the metadata is available separately.
I am able to load the json into a variant column, but cannot see how to parse and query for specific columns, e.g. Frankford below - I have tried JSONcol:data[0] which returns the entire entry, but am unable to see how to specify column 4, say.
{
data: [ [ "row-ea6u~fkaa~32ry", "0B8F94EE5292", 0, 1486063689, null, 1486063689, null, "{ }", "410", "21206", "Frankford", "2", "NORTHEASTERN", [ "{\"address\": \"4509 BELAIR ROAD\", \"city\": \"Baltimore\", \"state\": \"MD\", \"zip\": \"\"}", null, null, null, true ], null, null, null ]]
}
The following code is used to create and load the snowflake table:
create or replace table snowpipe.public.snowtable(jsontext variant);
copy into snowpipe.public.snowtable
from #snowpipe.public.snowstage
file_format = (type = 'JSON')
Not exactly sure how your varient data is look once you have loaded it, but experimenting on variant via PARSE_JSON for you object. Which I has to double slash the \ to make it valid sql.
select
PARSE_JSON('{ data: [ [ "row-ea6u~fkaa~32ry", "0B8F94EE5292", 0, 1486063689, null, 1486063689, null, "{ }", "410", "21206", "Frankford", "2", "NORTHEASTERN", [ "{\\"address\\": \\"4509 BELAIR ROAD\\", \\"city\\": \\"Baltimore\\", \\"state\\": \\"MD\\", \\"zip\\": \\"\\"}", null, null, null, true ], null, null, null ]]}') as j
,j:data as jd
,jd[0] as jd0
,jd0[3] as jd0_3
,array_slice(j:data[0],3,5) as jd0_3to4
;
shows that you can use [0] notation to index arrays, and thus get the results:
J: { "data": [ [ "row-ea6u~fkaa~32ry", "0B8F94EE5292", 0, 1486063689, null, 1486063689, null, "{ }", "410", "21206", "Frankford", "2", "NORTHEASTERN", [ "{\"a...
JD: [ [ "row-ea6u~fkaa~32ry", "0B8F94EE5292", 0, 1486063689, null, 1486063689, null, "{ }", "410", "21206", "Frankford", "2", "NORTHEASTERN", [ "{\"address\": \"4509 BELAIR ROAD\", \"city\": \"...
JD0: [ "row-ea6u~fkaa~32ry", "0B8F94EE5292", 0, 1486063689, null, 1486063689, null, "{ }", "410", "21206", "Frankford", "2", "NORTHEASTERN", [ "{\"address\": \"4509 BELAIR ROAD\", \"city\": \"Baltimore\", \"state\": \"MD\", \"...
JD0_3: 1486063689
JD0_3TO4: [ 1486063689, null ]
so if you have unknown amount of first level elements in data that you want to access, then use LATERAL FLATTEN like so:
WITH data as (
select PARSE_JSON('{ data: [ [ "row-1", "0B8", 0 ],["row-2", "F94", 2],
["row-3", "EE5", 4]]}') as j
)
select f.value[0]::text as row_name
,f.value[1]::text as serial_number
,f.value[2]::number as num
from data d,
lateral flatten(input=> d.j:data) f;
gives:
ROW_NAME SERIAL_NUMBER NUM
row-1 0B8 0
row-2 F94 2
row-3 EE5 4

Retrieving sub-fields from parsed JSON in snowflake

I'm having some difficulty getting the individual components of the address component
with data as (select
PARSE_JSON('{ "data" : [
[ "row-ea6u~fkaa~32ry", "00000000-0000-0000-01B7-0B8F94EE5292", 0, 1486063689, null, 1486063689, null, "{ }", "410", "21206", "Frankford", "2", "NORTHEASTERN", [ "{\"address\": \"4509 BELAIR ROAD\", \"city\": \"Baltimore\", \"state\": \"MD\", \"zip\": \"\"}", null, null, null, true ], null, null, null ]
}') as j
)
select f.value[1][0]::text
from data d,
lateral flatten(input=> d.j:data,recursive=>TRUE) f;
f.value[1][0] has a field address
{"address": "4509 BELAIR ROAD", "city": "Baltimore", "state": "MD", "zip": ""}
but
f.value[1][0].address returns null
How do I get the individual attributes of f.value[1] like address, city, etc?
The problem is given you have three levels of nested data, you should not be using recursive=>TRUE as the objects are not the same, so you cannot make anything of value out of the data. You need to break the different layers apart manually.
with data as (
select
PARSE_JSON('{ data: [ [ "row-ea6u~fkaa~32ry", "0B8F94EE5292", 0, 1486063689, null, 1486063689, null, "{ }", "410", "21206", "Frankford", "2", "NORTHEASTERN", [ "{\\"address\\": \\"4509 BELAIR ROAD\\", \\"city\\": \\"Baltimore\\", \\"state\\": \\"MD\\", \\"zip\\": \\"\\"}", null, null, null, true ], null, null, null ]]}') as j
), data_rows as (
select f.value as r
from data d,
lateral flatten(input=> d.j:data) f
)
select dr.r[0] as v0
,dr.r[1] as v1
,dr.r[2] as v2
,dr.r[3] as v3
,f.value as addr_n
from data_rows dr,
lateral flatten(input=> dr.r[13]) f;
so this get all the rows (of which your example has only one) the unpacks the values of interest (you will need to complete this part and give v0 - vN meaning) but there is an array or addresses
V0 V1 V2 V3 ADDR_N
"row-ea6u~fkaa~32ry" "0B8F94EE5292" 0 1486063689 "{\"address\": \"4509 BELAIR ROAD\", \"city\": \"Baltimore\", \"state\": \"MD\", \"zip\": \"\"}"
"row-ea6u~fkaa~32ry" "0B8F94EE5292" 0 1486063689 null
"row-ea6u~fkaa~32ry" "0B8F94EE5292" 0 1486063689 null
"row-ea6u~fkaa~32ry" "0B8F94EE5292" 0 1486063689 null
"row-ea6u~fkaa~32ry" "0B8F94EE5292" 0 1486063689 true
now to decode the address as json ,parse_json(f.value) as addr_n does that, so you can break it apart like:
with data as (
select
PARSE_JSON('{ data: [ [ "row-ea6u~fkaa~32ry", "0B8F94EE5292", 0, 1486063689, null, 1486063689, null, "{ }", "410", "21206", "Frankford", "2", "NORTHEASTERN", [ "{\\"address\\": \\"4509 BELAIR ROAD\\", \\"city\\": \\"Baltimore\\", \\"state\\": \\"MD\\", \\"zip\\": \\"\\"}", null, null, null, true ], null, null, null ]]}') as j
), data_rows as (
select f.value as r
from data d,
lateral flatten(input=> d.j:data) f
)
select dr.r[0] as v0
,dr.r[1] as v1
,dr.r[2] as v2
,dr.r[3] as v3
,parse_json(f.value) as addr_n
,addr_n:address::text as addr_address
,addr_n:city::text as addr_city
,addr_n:state::text as addr_state
,addr_n:zip::text as addr_zip
from data_rows dr,
lateral flatten(input=> dr.r[13]) f;
you can ether leave the addr_n dummy variable or swap it out by cut'n'pasting it like so:
,parse_json(f.value):address::text as addr_address
,parse_json(f.value):city::text as addr_city
,parse_json(f.value):state::text as addr_state
,parse_json(f.value):zip::text as addr_zip
You can follow the article for step-by-step for achieving it:
https://community.snowflake.com/s/article/Using-lateral-flatten-to-extract-data-from-JSON-internal-field
Hope this helps!

PostgreSQL 9.5.2 - Building a JSON object/String - Multiple 1:many relationships

I am playing with PostgreSQL building JSON objects/strings for a project.
I am new with the syntax and am looking for "best practices" in doing this.
Imagine the following tables (ignoring the design)
CREATE TABLE object (
item_id INT
,name VARCHAR(64)
,category_id INT
)
CREATE TABLE object_features (
item_id INT
,feature_1 VARCHAR(64)
,val_1 FLOAT
,feature_2 VARCHAR(64)
,val_2 FLOAT
,feature_3 VARCHAR(64)
,val_3 FLOAT
,feature_n VARCHAR(64)
,val_n FLOAT
)
CREATE TABLE category (
id INT
,name VARCHAR(64)
)
CREATE TABLE comment (
object_id INT
,name VARCHAR(64)
,date DATETIME
,score INT
)
How would you create the following JSON (or at least as close as possible)?
[{
"item_id": 1234,
"category": "category 1",
"name": "xyz",
"features": [{
"feature_1": "val_1",
"highlight": "Y"
}, {
"feature_4": "val_2",
"highlight": "Y"
}, {
"feature_3": "val_3",
"highlight": "N"
}, {
"feature_n": "val_n",
"highlight": "Y"
}],
"comments": [{
"name": "larry",
"date": "2016-04-01",
"score": 1
}, {
"name": "harry",
"date": "2016-03-01",
"score": 5
}]
}, {
"item_id": 434,
"category": "category 2",
"name": "dda",
"features": [{
"feature_1": "val_1",
"highlight": "N"
}, {
"feature_4": "val_2",
"highlight": "N"
}, {
"feature_3": "val_3",
"highlight": "N"
}, {
"feature_n": "val_n",
"highlight": "N"
}],
"comments": [{
"name": "merry",
"date": "2016-04-01",
"score": 1
}]
}]
Regards,
G

Parsing json files

Below is the code for visual analysis of a set of tweets obtained in a .json file. Upon interpreting , an error is shown at the map() function. Any way to fix it?
import json
import pandas as pd
import matplotlib.pyplot as plt
tweets_data_path = 'import_requests.txt'
tweets_data = []
tweets_file = open(tweets_data_path, "r")
for line in tweets_file:
try:
tweet = json.loads(line)
tweets_data.append(tweet)
except:
continue
print(len(tweets_data))
tweets = pd.DataFrame()
tweets['text'] = map(lambda tweet: tweet['text'], tweets_data)
These are the lines leading up to the 'ValueError' message I am getting for the above code :
Traceback (most recent call last):
File "tweet_len.py", line 21, in
tweets['text'] = map(lambda tweet: tweet['text'], tweets_data)
File "/usr/lib/python3/dist-packages/pandas/core/frame.py", line 1887, in setitem
self._set_item(key, value)
File "/usr/lib/python3/dist-packages/pandas/core/frame.py", line 1966, in _set_item
self._ensure_valid_index(value)
File "/usr/lib/python3/dist-packages/pandas/core/frame.py", line 1943, in _ensure_valid_index
raise ValueError('Cannot set a frame with no defined index '
ValueError: Cannot set a frame with no defined index and a value that cannot be converted to a Series
I am using Python3.
EDIT : Below is a sample of the twitter data collected ( .json format).
{
"created_at": "Sat Mar 05 05:47:23 +0000 2016",
"id": 705993088574033920,
"id_str": "705993088574033920",
"text": "Tumi Inc. civil war: Staff manning US ceasefire hotline 'can't speak Arabic' #fakeheadlinebot #learntocode #makeatwitterbot #javascript",
"source": "\u003ca href=\"http://javascriptiseasy.com\" rel=\"nofollow\"\u003eJavaScript is Easy\u003c/a\u003e",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 4382400263,
"id_str": "4382400263",
"name": "JavaScript is Easy",
"screen_name": "javascriptisez",
"location": "Your Console",
"url": "http://javascriptiseasy.com",
"description": "Get learning!",
"protected": false,
"verified": false,
"followers_count": 167,
"friends_count": 68,
"listed_count": 212,
"favourites_count": 11,
"statuses_count": 55501,
"created_at": "Sat Dec 05 11:18:00 +0000 2015",
"utc_offset": null,
"time_zone": null,
"geo_enabled": false,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"profile_background_color": "000000",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_link_color": "FFCC4D",
"profile_sidebar_border_color": "000000",
"profile_sidebar_fill_color": "000000",
"profile_text_color": "000000",
"profile_use_background_image": false,
"profile_image_url": "http://pbs.twimg.com/profile_images/673099606348070912/xNxp4zOt_normal.jpg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/673099606348070912/xNxp4zOt_normal.jpg",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/4382400263/1449314370",
"default_profile": false,
"default_profile_image": false,
"following": null,
"follow_request_sent": null,
"notifications": null
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 0,
"favorite_count": 0,
"entities": {
"hashtags": [{
"text": "fakeheadlinebot",
"indices": [77, 93]
}, {
"text": "learntocode",
"indices": [94, 106]
}, {
"text": "makeatwitterbot",
"indices": [107, 123]
}, {
"text": "javascript",
"indices": [124, 135]
}],
"urls": [],
"user_mentions": [],
"symbols": []
},
"favorited": false,
"retweeted": false,
"filter_level": "low",
"lang": "en",
"timestamp_ms": "1457156843690"
}
I think you can use read_json:
import pandas as pd
df = pd.read_json('file.json')
print df.head()
contributors coordinates created_at entities \
contributors_enabled NaN NaN 2016-03-05 05:47:23 NaN
created_at NaN NaN 2016-03-05 05:47:23 NaN
default_profile NaN NaN 2016-03-05 05:47:23 NaN
default_profile_image NaN NaN 2016-03-05 05:47:23 NaN
description NaN NaN 2016-03-05 05:47:23 NaN
favorite_count favorited filter_level geo \
contributors_enabled 0 False low NaN
created_at 0 False low NaN
default_profile 0 False low NaN
default_profile_image 0 False low NaN
description 0 False low NaN
id id_str \
contributors_enabled 705993088574033920 705993088574033920
created_at 705993088574033920 705993088574033920
default_profile 705993088574033920 705993088574033920
default_profile_image 705993088574033920 705993088574033920
description 705993088574033920 705993088574033920
... is_quote_status lang \
contributors_enabled ... False en
created_at ... False en
default_profile ... False en
default_profile_image ... False en
description ... False en
place retweet_count retweeted \
contributors_enabled NaN 0 False
created_at NaN 0 False
default_profile NaN 0 False
default_profile_image NaN 0 False
description NaN 0 False
source \
contributors_enabled <a href="http://javascriptiseasy.com" rel="nof...
created_at <a href="http://javascriptiseasy.com" rel="nof...
default_profile <a href="http://javascriptiseasy.com" rel="nof...
default_profile_image <a href="http://javascriptiseasy.com" rel="nof...
description <a href="http://javascriptiseasy.com" rel="nof...
text \
contributors_enabled Tumi Inc. civil war: Staff manning US ceasefir...
created_at Tumi Inc. civil war: Staff manning US ceasefir...
default_profile Tumi Inc. civil war: Staff manning US ceasefir...
default_profile_image Tumi Inc. civil war: Staff manning US ceasefir...
description Tumi Inc. civil war: Staff manning US ceasefir...
timestamp_ms truncated \
contributors_enabled 2016-03-05 05:47:23.690 False
created_at 2016-03-05 05:47:23.690 False
default_profile 2016-03-05 05:47:23.690 False
default_profile_image 2016-03-05 05:47:23.690 False
description 2016-03-05 05:47:23.690 False
user
contributors_enabled False
created_at Sat Dec 05 11:18:00 +0000 2015
default_profile False
default_profile_image False
description Get learning!
[5 rows x 25 columns]