Table to JSON

Hello,

I got a task to convert a table into JSON as in the TXT file. I’ve already tried table to json but only this came out of here:

Is there a good and quick solution for this?
Example_Workflow.knwf (4.6 KB)
JSON_example.txt (366 Bytes)

Thank you

Hi @goodvirus, Could you re-post/edit as your posted solution is missing your solution (i.e. it just has the Table Creator node) :wink:

I think though, but I may be wrong, that what @CyberCrimeFlo is wanting to do is generate a json txt file in the same format as the txt file example, rather than reading and parsing the json from the txt file. Maybe @CyberCrimeFlo can confirm that . thanks

1 Like

Hi,

you can also use the JSON-Reader to prase the text. After this you have to use JsonPath.
See the Solution attached.
Solution.knwf (24.9 KB)

Best Regards,

Paul

If takbb is correct in his understandig of the topic here another solution, hope it helps.
Solutionv2.knwf (9.1 KB)

Hey @takbb and @goodvirus,

@takbb you are right I have this table and should convert it to json like the txt

Thank you

Hi @CyberCrimeFlo ,

I have managed to create a file in (approximately) the format you require, I think. The one thing I couldn’t find a way of achieving is not outputting “null” for the values that are missing. In your example, these don’t show. I’m hoping that this won’t present a problem, but if so, maybe somebody else can assist, or perhaps some other text-file parsing could be used to remove these lines.

I’m also assuming that the ordering of the fields in the generated json is unimportant. I don’t think it should be important but it depends how you subsequently process them. If the order is important, then you should be able to fix that by putting a Column Resorter node as the first node after the Table Creator, to put the columns into the required order.

Anyway, the trick I used here was to generate initially the JSON for all columns except Aktionscode. So you have the “json detail” for the remaining columns. I then grouped everything by Aktionscode, renamed the columns as required for the output, and then generated JSON for both the “code” column, and the already generated json columns from earlier.

This effectively placed the “detail” json inside the code, so the generated object looks like this:

image

Generate Json grouped by code.knwf (56.3 KB)

I hope that helps move you in the right direction

3 Likes

Hi @takbb,

Thank you very, very, very much!

That helps me a lot and I am learning through the workflow.

Thanks again that is very helpful

3 Likes

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