'convert JSON to TSV using pandas
I would like to convert JSON to TSV but not from a file or to a file.
messages = {
"1":[
{
"id":"4d9edf9b-ab9a-45bc-a453-3ea9ecc97818",
"message":"m1",
"access": "*"
},
{
"id":"7c4b41e4-3e4f-40ed-9aa4-3854a6b3706a",
"message":"m2",
"access": "*"
},
{
"id":"c1c332cf-7cb4-4c5e-bf85-3d7ae3a11625",
"message":"m3",
"access": "*"
},
{
"id":"dc9b47b9-d325-475d-9994-a4269faa0873",
"message":"m4",
"access": "*"
}
]
}
> import sys
> import pandas as pd
> table = pd.read_json(messages[1], orient='records')
> table.to_csv(sys.stdout, sep='\t', index=False)
I tried something like this but it did not work. please help me
Solution 1:[1]
To convert the list of Json into DataFrame you should
table=pd.DataFrame.from_records(messages["1"])
then save as you did in the post .
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | shani klein |
