I have a JSON file with a field named "AdditionalFields" as below-
"additionalFields":
[
{
"fieldName":"customer_name",
"fieldValue":"ABC"
},
{
"fieldName":"deviceid",
"fieldValue":"1234"
},
{
"fieldName":"txn_id",
"fieldValue":"2"
},
{
"fieldName":"txn_date",
"fieldValue":"2017-08-14T18:17:37"
},
{
"fieldName":"orderid",
"fieldValue":"I126101"
}
]
How to parse this as separate columns? eg customer name to be a column and ABC should be the value.
Tried to parse this as an ArrayType but getting multiple rows for columns "FieldName" and "FieldValue".
Want to get each item under FieldName to be a column & FieldValue to be the respective column value.
2
Answers
I hope this is how your sample data looks like:
This is how it looks like:
Output:
Depending on the size of your JSON, you can also open it using the
json
library and create the DataFrame data by working on the dictionaries: