# ScriptTask: Unable save javascript json object as variable

**URL:** <https://forum.flowable.org/t/scripttask-unable-save-javascript-json-object-as-variable/8813>\
**Category:** Uncategorized\
**Created:** [January 5, 2022, 6:28am UTC](https://forum.flowable.org/t/scripttask-unable-save-javascript-json-object-as-variable/8813 "2022-01-05T06:28:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vamshichanda](https://avatars.discourse-cdn.com/v4/letter/v/9dc877/32.png) [@vamshichanda](https://forum.flowable.org/u/vamshichanda)\
**Post date:** [January 5, 2022, 6:28am UTC](https://forum.flowable.org/t/scripttask-unable-save-javascript-json-object-as-variable/8813/1 "2022-01-05T06:28:48Z")

</div>

Hi,  
I’m trying to run a javascript code using the script task. We are using the secure javascript module.  
The script we are trying to execute is

```auto
var batchExport = {};
batchExport.exportProfile = "testProfile"; 
batchExport.batchName = "rrrrrr";

execution.setVariable("aaa",batchExport);

```

When we are trying to execute this getting error like,

```auto
org.flowable.common.engine.api.FlowableException: Couldn't serialize value '[object Object]'

```

Can someone help on how to resolve this.

Thanks…

---

<div class="post-metadata">

**Author:** ![maudrid](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@maudrid](https://forum.flowable.org/u/maudrid)\
**Post date:** [January 11, 2022, 11:47am UTC](https://forum.flowable.org/t/scripttask-unable-save-javascript-json-object-as-variable/8813/2 "2022-01-11T11:47:27Z")

</div>

One way to work around this is as follows:  
execution.setVariable(“aaa”,JSON.stringify(batchExport));

var batchExport = JSON.parse(execution.getVariable(“aaa”));

---

<div class="post-metadata">

**Author:** ![vamshichanda](https://avatars.discourse-cdn.com/v4/letter/v/9dc877/32.png) [@vamshichanda](https://forum.flowable.org/u/vamshichanda)\
**Post date:** [January 12, 2022, 7:33am UTC](https://forum.flowable.org/t/scripttask-unable-save-javascript-json-object-as-variable/8813/3 "2022-01-12T07:33:47Z")

</div>

Hi @maudrid,  
Thanks for the workaround.  
But i feel like there is should be some native support for this.

---

<div class="post-metadata">

**Author:** ![maudrid](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@maudrid](https://forum.flowable.org/u/maudrid)\
**Post date:** [January 12, 2022, 2:33pm UTC](https://forum.flowable.org/t/scripttask-unable-save-javascript-json-object-as-variable/8813/4 "2022-01-12T14:33:05Z")

</div>

The problem is not with flowable.  
Java does not know how to serialise a javascript object.

---

<div class="post-metadata">

**Author:** ![vamshichanda](https://avatars.discourse-cdn.com/v4/letter/v/9dc877/32.png) [@vamshichanda](https://forum.flowable.org/u/vamshichanda)\
**Post date:** [January 12, 2022, 3:30pm UTC](https://forum.flowable.org/t/scripttask-unable-save-javascript-json-object-as-variable/8813/5 "2022-01-12T15:30:39Z")

</div>

Hi,  
I never said the problem is with flowable. I just expressed that it would be helpful if flowable had some kind of support to handle the javascript json objects.  
We are using the secure javascript until and so the rhino engine is at the background running the scripts.  
As I understand, rhino parses the javascript objects inside the instance of a NativeObject. NativeObject by itself is Serializable(from doc). But because of some flowable secure javascript scope object reference, the serialization is failing. In this case it kind of seems a problem on the flowable end.  
I’m sorry if I got anything wrong.

Thanks.

---

<div class="post-metadata">

**Author:** ![prasanta](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/prasanta/32/2864_2.png) [@prasanta](https://forum.flowable.org/u/prasanta)\
**Post date:** [January 9, 2023, 1:50pm UTC](https://forum.flowable.org/t/scripttask-unable-save-javascript-json-object-as-variable/8813/6 "2023-01-09T13:50:00Z")

</div>

Hi @vamshichanda We are facing similar issue. Below issue

1. We are using SecureScriptExecutor for whitelisting java classes.
2. While trying to access a field of json variable in script task, we are getting undefined. Somehow rhino engine unable to execute variable having json type.  
var student = execution.getVariable(“student”)//Here student is json type  
execution.setVariable(“student\_name”, student.name);//Here student\_name is becoming undefined as rhino engine is unable to process json variable.
