-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flatten a Parent-child json #280
Comments
Only with one transformation, that doesn't seem possible. Transformer: {
"result": {
"#transform($)": [{
"Children": "#valueof($..Children)"
}, {
"intermediate": {
"#loop($.Children)": {
"Items": "#currentvalueatpath($[0].Items)",
"Path": "#currentvalueatpath($[0].Path)"
}
}
},
"#valueof($.intermediate)"
]
}
} Output: {
"result": [{
"Items": [{
"Id": "66717101"
}, {
"Id": "66717102"
}
],
"Path": "Type1~Cat1"
}, {
"Items": [{
"Id": "66717101"
}
],
"Path": "Type1~Cat1~Sku1"
}, {
"Items": [{
"Id": "66717102"
}
],
"Path": "Type1~Cat1~Sku2~Model1"
}, {
"Items": [{
"Id": "66717722"
}
],
"Path": "Type1~Cat1~Sku2~Model1"
}, {
"Items": null,
"Path": null
}, {
"Items": null,
"Path": null
}
]
} |
We have created 2 custom fields to achieve the same thing. One function to flatten it by field path and other to identify jarray and flatten it recursively. public static JArray FlattenNestedJson(JArray source, string fieldPath)
See if this helps and @Courela let me know if you want me to add this function and create PR. |
I tried to achieve from solution provided by @vikasagrawal
I wonder if so many intermediate steps/ loops are OK to achieve it.. |
#loopwithincontext? Seems that you're using an old version. |
Sure, I'll check if we can upgrade to the latest version. If not, would the transformer mentioned above be suitable from a practical perspective? |
as of now going with above solution: #280 (comment) Thanks @vikasagrawal @Courela |
hi @Courela
trying to find some nested loop kind of functionality to flatten below parent-child structure. Can you suggest how to proceed on this:
Input:
Output:
The text was updated successfully, but these errors were encountered: