# JSON proces variables - any gotchas?

**URL:** https://forum.flowable.org/t/json-proces-variables-any-gotchas/1798
**Category:** Flowable Engine
**Created:** [March 27, 2018, 7:54am UTC](https://forum.flowable.org/t/json-proces-variables-any-gotchas/1798 "2018-03-27T07:54:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![pieterclaeys](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/pieterclaeys/32/608_2.png) [@pieterclaeys](https://forum.flowable.org/u/pieterclaeys)
#### Post date: [March 27, 2018, 7:54am UTC](https://forum.flowable.org/t/json-proces-variables-any-gotchas/1798/1 "2018-03-27T07:54:08Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![mgrouch](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@mgrouch](https://forum.flowable.org/u/mgrouch)
#### Post date: [March 27, 2018, 4:06pm UTC](https://forum.flowable.org/t/json-proces-variables-any-gotchas/1798/2 "2018-03-27T16:06:52Z")

</div>

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

---

<div class="post-metadata">

### Author: ![PeterCahn](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@PeterCahn](https://forum.flowable.org/u/PeterCahn)
#### Post date: [August 30, 2018, 8:03am UTC](https://forum.flowable.org/t/json-proces-variables-any-gotchas/1798/3 "2018-08-30T08:03:09Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![chaserb](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/chaserb/32/3084_2.png) [@chaserb](https://forum.flowable.org/u/chaserb)
#### Post date: [April 6, 2023, 10:45pm UTC](https://forum.flowable.org/t/json-proces-variables-any-gotchas/1798/4 "2023-04-06T22:45:06Z")

</div>

Hello @PeterCahn , I believe the reason it worked for @pieterclaeys is that his `scriptTask` likely specified `scriptFormat="groovy"`. Without that attribute, the default script format is JavaScript, which I’m guessing you are using based on the sample code you have above.
