Please help to transform below input json to mentioned output format.
Noteworthy: Input JSON start as an object and there is another object 2 within it. Output JSON expectation is to merge into 1 object.
I don’t know if you have managed to resolve your problem already, as you posted about this 4 days ago. I was wondering if your actual question is more generic than it appears, as it seems very specific to the particular data that you have. This always concerns me a little, since if you are trying to have some form of general process that can be used to achieve future transformations, it may be that certain “rules” need to be stated.
For example, should you always just remove “object 2” from the result. Is “object 2” always at the beginning of the json array?
Without additional more general information, the solution I have come up with achieves the required output based on the example data given, but isn’t particularly “general purpose”, so that may be what you are requiring, but if you need something more generalised then you will need to specify more detail.
I suspect that the question of providing a more generalised solution is the primary reason for the lack of responses. Certainly it had given me to question how this solution should be approached.
Anyway, I hope this is useful, or at least gives some pointers.
@takbb Thank you so much for taking out time to provide this solution.
Yes, I did manage to solve by using series of Column expressions with replace function etc. , but that doesn’t sound to be an apt solution as compared with yours. Also, I did miss a trick of Groupby(List) and converting back to JSON.
Way I handled:
replace(replace(column(“JSON”), “[[”,“[” ),“]]”,“]”)
replace(replace(replace(column(“JSON (#1)”),“[{"Key 1” ,“{"Key 1” ),“},{"Object 1”,“,"Object 1”),“}]}]”, “}]}”)
Yes, you’re correct this is not a generalized requirement, which may vary if JSON structure changes tomorrow. Having said that, I am expecting entries to be dynamic in the inner object and I feel this can also be managed within your solution.
I happen to have a way forward from here. Thanks again for working this out.