OL Learn

JSON as sample data file in workflow

Hello,

Recently I’ve been making some datamappers based on json data files, and now I want to start making some processes in the workflow that use them. The problem is that I can not use the data selector on the json files, and I need to do that in order to set some local variables in the beginning of the processes, before executing the data mapping and content creation. Converting the JSON to XML to get the variables and then converting it back to JSON to execute the data mapping is not a good option as it takes too much time (the process is time critical so the speed should be considered).
The emulation set to XML does not work, and I am not sure how to use the other emulations for this as they are grid format and use number locations instead of paths as I would need for JSON.
Any idea how I could solve this?
Thank you in advance!

Hello @Cristian,

Here is a basic example of how you can set local variables by parsing a json:

var comand = Watch.ExpandString("%c");
Watch.Log(comand,2);

var commandDetails = JSON.parse(comand);

set (“id_client”, commandDetails.id_client);

function set(name, value) { typeof name === ‘number’ ? Watch.setJobInfo(name, value) : Watch.setVariable(name, value) }
function get(name) { return typeof name === ‘number’ ? Watch.getJobInfo(name) : Watch.getVariable(name) }

Regards,
Alexandru

2 Likes

@fsh22: I really like your shortcut functions set() and get(). I think I might borrow that idea in one of my next articles on the blog.

1 Like

@Phil Still learning and discovering new things over here :smiley:
Cheers!