简体   繁体   中英

Convert a Json to csv using python pandas

I have a json file in the below format that I need to convert to csv in python.

{
  "data": {
    "clientApplicationRsaKeyss": [
      {
        "clientId": "abc-efg",
        "createdOn": "2021-02-26T08:45:43.2746397Z"
      },
      {
        "clientId": "xyz-lmn",
        "createdOn": "2022-05-23T16:11:59.435729Z"
      },
]
}
}

I need to convert the above into a csv with the below fields:

clientID          createdon
abc-efg          2021-02-26T08:45:43.2746397Z
xyz-lmn          2022-05-23T16:11:59.435729Z

How do I do this using python / dataframe?

Its easy to do

>>> df = pd.DataFrame(json.load(open("test.json"))["data"]["clientApplicationRsaKeyss"])
>>> df 
  clientId                     createdOn
0  abc-efg  2021-02-26T08:45:43.2746397Z
1  xyz-lmn   2022-05-23T16:11:59.435729Z
>>> df.to_csv(".....", index=False)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM