I need to create a json following this model from a df using python.
I tried to load this json into a df to find the correct layout but did not succeed.
Can anyone help me or at list give me some hints?
Thanks in advance
{
"products": [
{
"productId": 123456790,
"quantaty": 10,
"orderLine": "10",
"buyerRef": "my ref"
},
{
"productId": 123456791,
"quantaty": 15,
"orderLine": "20",
"buyerRef": "my ref"
}
],
"costId": 109,
"paymentMethod": "termTransferWire",
"totalPriceTaxIncl": 1200,
"deliveryAddressId": 218,
"buyerOrderNumber": "Test",
"documentationRequestedName": [
"document 1",
"document 2"
]
}
3
Answers
First create a dictionary of your json object
Now in this dictionary, the json_obj.values can be considered as rows, and json_obj.keys can be considered as columns.
Create a new list for columns and rows
Now, import the pandas library and create your data frame as follows:
Try this:
Try like this
The resulting json_data will be a dictionary following the structure you provided. You can use the json.dumps method to convert it to a JSON string if needed:
import json