Parsing Complex JSON With Java Snippet?

I’ve been having difficulty getting Knime to process the data I want. I have a complex JSON object with nested arrays of objects. All my attempts to get the data in some other form either wind up with JSON code inside a cell (meaning, I can’t loop through it) or flattening the entire object and making it impossible to process.

I have an array of objects nested inside the JSON, and while I can get to it and save that in a cell, I can’t seem to iterate through them to process them (see above comment). I won’t know how many elements are in the array, so I can’t tell the node to process by indexes, either. I need to be able to iterate over the array extracted from a nested JSON attribute.

The Question: Is it possible to pass JSON to a Java Snippet and have it return rows and columns? From what I’ve read, it seems that’s not possible, but I wanted to ask.


Hi there!

Passing JSON to a Java Snippet node is possible. Manipulating with it depends on your Java knowledge :wink: I have composed an example using org.json library. Jar file and data sample is within workflow that is attached.

Here is an external link that helped me get started.

2019_02_12_JSON_parsing_with_Java.knwf (105.7 KB)