1

We query a df by below code:

json.loads(df.reset_index(drop=True).to_json(orient='table'))

The output is:

{"index": [ 0, 1 ,2, 3, 4],
 "col1": [ "250"],
 "col2": [ "1"],
 "col3": [ "223"],
 "col4": [ "2020-06-12 14:55"]
}

We need the output should be like this:

[ "250", "1", "223", "2020-06-12 14:55"],[.....][.....]
Balaji Ambresh
  • 4,977
  • 2
  • 5
  • 17
Elsa
  • 1
  • 1
  • 8
  • 27

3 Answers3

2
json.loads(df.reset_index(drop=True).to_json(orient='values')) 

change table into values solved my problem.

Elsa
  • 1
  • 1
  • 8
  • 27
0

What you call a "json" (there is no such data type) is a Python dictionary. Extract the values for the keys of interest using list comprehension:

x = .... # Your dictionary
[x[col][0] for col in x if col.startswith("col")]
#['250', '1', '223', '2020-06-12 14:55']
DYZ
  • 55,249
  • 10
  • 64
  • 93
  • `json.loads(df.reset_index(drop=True).to_json(orient='values')) ` change `table` into `values` solved my problem. – Elsa Jul 06 '20 at 06:10
0

We convert json to dataframe and we remove column name.

pd.Dataframe(json_source,header='False')

Then we convert it to json formate

df.to_json(orient='table')
  • `json.loads(df.reset_index(drop=True).to_json(orient='values')) ` change `table` into `values` solved my problem. – Elsa Jul 06 '20 at 06:09