I have a particular Json file about data. I'd like to convert it to a Data Frame and apply some transformation. Here is the Json:
{
"OuterVariable1": [
{
"InnerData": "car",
"InnerList": {
"wheels": {
"cost-taxed": 231,
"cost": 850
},
"engine": {
"cost-taxed": 108,
"cost": 286
}
}
},
{
"InnerData": "van",
"InnerList": {
"frame": {
"cost-taxed": 302,
"cost": 250
}
}
},
],
"OuterVariable2": [
{
"InnerData": "truck",
"InnerList": {
"wheels": {
"cost": 1400
},
}
},
],
...
}
Here is what I want. Notice how OuterVariable
is a new column, and we separate the entries for each InnerList
.
OuterVariable | InnerData | InnerList | Cost |
---|---|---|---|
OuterVariable1 | "car" | "wheels" | 850 |
OuterVariable1 | "car" | "engine" | 286 |
OuterVariable1 | "van" | "frame" | 250 |
OuterVariable2 | "truck" | "wheels" | 1400 |
How can I achieve this? I've used jsonlite
to get an initial DataFrame and tried to use lapply
to do some transformation with no luck.