Forum Discussion
Hello @alex.panganiban.guild,
You cannot access the ‘name’ field directly because as you said, you have a mixed data type array. You first need to access the object, and than the field that you need from that object. So , if you need to get the index number of an object, you can use this function:
$arrayField.findIndex(x=>typeof x == “object”)
And if you want the index number of the ‘name’ path of that object, you can use the following function:
$arrayField[$arrayField.findIndex(x=>typeof x == “object”)].keys().findIndex(x=>x == ‘name’)
Hope you’ll find this helpful,
Regards,
Bojan
- marjan_karafilo4 years agoContributor
Hi @amardeep2021
As @cjhoward18 mentioned, you can achieve this by using “filter”.Here is the input of the file:
Expression in mapper:
Output:
BR,
Marjan - cjhoward184 years agoEmployee
Hi,
You can achieve this by using a mapper snap with the following expression:
$.filter(value => value != null)
mapped to the target path$
this will filter all values out that equal null, keeping only the key-value pairs in which the value is not null.Keep in mind this will only work for 1 level of nesting as I noticed your data was. If it does need to work with nested JSON fields it would be a different expression that I can provide you with as well if needed.
- amardeep20214 years agoNew Contributor III
Thanks Cole. Kindly share the other expression also.
Regards,
Amar.- cjhoward184 years agoEmployee
You can use this expression:
{ filterEmptyKeys: (value, key) => value != null, cleanupTree: value => value instanceof Object ? value.mapValues(this.cleanupTree).filter(this.filterEmptyKeys) : value }.cleanupTree($)
mapped to the target path
$
to remove all null values from a nested JSON object
- amardeep20214 years agoNew Contributor III
Thanks Cole again. For the first expression, I am getting none null columns all coming as array for each rows. Is that expected?
- cjhoward184 years agoEmployee
Not sure what you mean. Can you share a version of the input-output example?
Related Content
- 4 years ago