JSON proces variables - any gotchas?

Hi,
to our pleasant surprise, and after a hint from Joram, we started using the JSON Type proces variable in our code - and so far seems to work out of the box (using flowable 6.2.0) . Great!
Even with script task we can use this:

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; 
JsonNode json = new ObjectMapper().readTree('{"array":[1,2,3],"boolean":true,"string":"stringvalue","number":1}');
execution.setVariable("test", json);

And we can use a JUEL expression to access fields of JSON variable:

${execution.setVariable("resultString", test.string)}
${execution.setVariable("resultBoolean", test.boolean)}
${execution.setVariable("resultNumber", test.number)}

Just one question: The JSONtype proces variable is hardly documented. Should we be suspicious / are there any gotchas? Or was it just a matter of lack of time that this isn’t really documented?

1 Like

Does it let you save bigger objects in DB than in serialized form?
I also know that serialized variables are not retrieved by join SQL queries issued by flowable.
In case of JSON tree they will be stored as text and retrieved. Could be a good or a bad thing for performance
depending on a use case.

Thanks

Hi,
I tried the approach in a script task, but it gives me the following error (with Flowable 6.3.1):

Caused by: jdk.nashorn.internal.runtime.ParserException: :11:0 Expected an operand but found import
import com.fasterxml.jackson.databind.JsonNode;

Then I changed it in the following to make it work:

var ObjectMapper = com.fasterxml.jackson.databind.ObjectMapper;

var test = {};
test.value1 = "string1";
test.value2 = "string2";

var testJson = JSON.stringify(test);
var json = new ObjectMapper().readTree(testJson);
execution.setVariable("test", json);

From here I can access the variables as you said with the dot notation (i.e. test.string1 etc…).

Thank you very much for your hints that saved my day!

Regards.