How to work with name-value pairs (JSON) in a variable array

Michael M1
Giga Expert

I have a variable that is a JSON array of name-value pairs. I want to iterate over the pairs and remove the empty/null values. Can I use the JsonNodeIterator feature for this? I cannot find the JsonNode class in my script includes (London).

Thoughts?

2 REPLIES 2

HV1
Mega Guru

This might help: https://stackoverflow.com/questions/23774231/how-do-i-remove-all-null-and-empty-string-values-from-a-json-object/23774287

 

Abhinay Erra
Giga Sage

I usually iterate through the json object and delete the key if the value is null, undefined or empty

 

 for (var propName in jsonObj) {
    if (jsonObj[propName] === null || jsonObj[propName] === undefined ||jsonObj[propName]=='' ) {
      delete jsonObj[propName];
    }
  }