change exported JSON format

Hi,

I want to export data from KNIME into a JSON format as follows:

  "values": [
    [      -15.42, 95    ],
    [      -15.36, 95    ],
...

and I have a data a normal table:

1.0       579.9
2000.0    586.2
500.0     581.4

I tried several combinations of the “Transpose”- and “Table to JSON”-node and the best outcome is a transposed version and the “column oriented” “aggration column” (see attached workflow json1.knwf (10.4 KB)):

{
  "Row0" : [ 1.0, 33.3 ],
  "Row1" : [ 2000.0, 111.1 ],
  "Row2" : [ 500.0, 55.5 ]
}

that still needs changes like removing the rowid, adding brackets and “values”,

Is there a easy way to change it or do I have to use editng of the JSON?

Hello @spider
As you probably tried already, I’ve been trying to find a straight forward node configuration but I couldn’t. For this specific request I think that you will have to customize your JSON file.

I’ve prepared a simple example workflow as a custom solution, it’s based in your shared workflow:

BR

3 Likes

Hey there,
i do not understand how you calculate the values ’ -15.42’ in the first row, but here is a solution how to create the JSON fast and easy.

Hub Link

Hope that helps,
Alex

4 Likes

Thanx @Alex_JW

In fact mor efficient.

BR

1 Like

Thanks very much for that trick.

1 Like

Hey spider,
i just noticed that you can cut the column rename, since you can change the column name to ‘values’ directly inside the column aggregator node (options → aggregation settings → Column name).

Alex

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.