Forum Discussion
I think the data that you are sharing and the data that you are working with are completely different. I suggest you to share the actual data that you are working with and if there is some sensitive information just replace it with “X” or something else, because what we need is the actual format of the data.
Here is the json file. This is the actual output format.
mapping_SAP output output0.zip (1.6 KB)
- j_angelevski4 years agoContributor III
Okay, I can see that the last property is an object not an array, that’s why it is failing. I am referring to “EH_RETURN” in your data. Removing that object, the expression works. I will update my expression and give you a solution where it checks whether the property is an object or array, this was unexpected.
- j_angelevski4 years agoContributor III
I updated the expression, please refer to the following one:
{}.extend(...$data.entries().map(val => typeof val[1] == "object" ? ({val[0]]: val[1].mapValues((v, k) => k.contains("_DATE") && v == null ? "0000-00-00" : v})) : {[val[0]]: val[1].map(v => {}.extend(...v.entries().map(date => date[0].contains("_DATE") && date[1] == null ? {[date[0]]: "0000-00-00"} : {[date[0]]: date[1]} )))}))
Or this one ( with match operator ):
{}.extend(...$data.entries().map(val => match typeof val[1] { "object" => { [val[0]]: val[1].mapValues((v, k) => k.contains("_DATE") && v == null ? "0000-00-00" : v) }, "array" => { [val[0]]: val[1].map(v => {}.extend(...v.entries().map(date => date[0].contains("_DATE") && date[1] == null ? {[date[0]]: "0000-00-00"} : {[date[0]]: date[1]} ))) } } ))
- aditya_gupta414 years agoContributor
This works. Thanks for your help @j.angelevski