Converting Large JSON to Spin and back to native JSON in JavaScript


We have a large JSON Payload which i am getting using the http-connector response. As the JSON is large i have to convert it to SPIN using the S(response) option and store it in the variable. If i am not doing that i am getting the 4k limit exception.
Now as part of the other Task i have to send the actual JSON as received for further processing.
I tried converting the Spin object back to JSON using the toString() and storing in the input parameters and its throwing the 4k exception again.
How can we store the JSON variables as is / How can we convert the SPIN object back to JSON without encountering the 4k limit exception. Any help here is highly appreciated.

Sai Arun J

@arun280780 what does this mean? What is the “other task” doing? what type of task is it?

The general workaround is that you keep it in SPIN format until the very last second which is when you actually need to pass it into the function/variable in your code that requires json string; at which point you do the .toString()

@StephenOTT. Thank you so much for your response.
To give you a quick background :
We are using Angular 4 components for the UI (MEAN STACK) and we are using the camunda rest API to get and set the variables for the Form. We have developed this workflow totally using the inline JavaScript capability of camunda.

Now to answer your question:
The other Task here is a user task. where we wanted to load the angular UI. which accepts the JSON data to load it self. we are using the task get variable api to get this input parameter.

Once i set the variable to any of the execution parameter it throws the exception. Please suggest an alternative if any?

One quick workaround is to use the SPIN on the angular side as well to convert the SPIN back to Json. if you have any details on how to get the SPIN java script i can try to use it on the Node and convert the SPIN object back to JSON for consumption.

Sai Arun J

When you set your input parameter, just set it for the SPIN variable.

Then when you use the rest api and call GET /task/:id/variables/ set the param: deserializeValues=false. This will return the JSON as a stringified. Then in your web app just do a JSON.parse() of the string to convert it back into JS JSON.

see the docs:

1 Like

Hi @StephenOTT,

Thank you very much using the flag did solve my problem. really appreciate your help here.

Sai Arun J