Write JSON File

Hello.

Is there a way to encapsulate an workflow output into a JSON file on KNIME?

 

Thanks !

 

Hi Joana,

...not yet - but JSON I/O and processing nodes (similar to the XML node set) are pretty high on our list of things that we'd like to add... Is there a particular reason why you are asking?

I guess for now doing a manual work around via the String Manipulator (or one of the Snippet) nodes is the way to go.

Michael

Hi berthold.

So the way to surrond this is probably to use a Java Snippet with a JSON library to transform this output am I rigth?

 

Thanks !

This could be an option, yes. You can also do it manually, I guess. Here would be java snippet piece that would take all columns (convert numbers to strings first!) and combines their values into a json object. You can also mess around with FileWriters already and write the data to a file.

StringBuilder b = new StringBuilder("{ ");
for (int i = 0; i < getColumnCount(); i++) {
    b.append(i == 0 ? "" : ", ");
    b.append("\"").append(getColumnName(i)).append("\":");
    b.append(getCell(i, ""));
}
b.append(" }");
out_json_s = b.toString();

... could work?