Extracting optional values from JSON array of nested JSON objects

Sometimes you want to extract values from a JSON array and transform them into a KNIME table such that one row corresponds to a single value of the array. If the JSON array is nested, i.e., if it contains JSON objects or arrays itself, you sometimes do not want to extract its full values, but only parts thereof. These values can be optional in the sense that they are not present in all values of the array. This workflow explores options for extracting such optional values from a JSON array of nested JSON objects.


This is a companion discussion topic for the original entry at https://kni.me/w/sUT2oHpnGNqXKC2Y
2 Likes

The JSON array which this workflow reads via the JSON Reader nodes looks like this:

[ 
   { 
      "mandatoryInnerNode":{ 
         "mandatoryLeafInMandatoryInnerNode":"foo"
      }
   },
   { 
      "mandatoryInnerNode":{ 
         "mandatoryLeafInMandatoryInnerNode":"foo",
         "optionalLeafInMandatoryInnerNode":"bar"
      },
      "optionalInnerNode":{ 
         "mandatoryLeafInOptionalInnerNode":"baz"
      }
   }
]

Hi, it’s a bit unclear to me what to put in the first JSON path node, my array looks like your example but i’m unable to get a single line for each structure in the array, that is my final goal having this kind of structure is to have a single line for each entity of LAP and the line will conain some paramterers of the father object session and some parameters of the Laps Object.
But firstly in need to separate each runsheet object of the main json list.

[
{"$type" : “RunSheet”, “Id” : “1234”, Parameters : { …, “Laps” : [ {…},{…}] } },
{"$type" : “RunSheet”, “Id” : “1234”, Parameters : { …, “Laps” : [ {…},{…}] } },
…
]

Thanks.