How to validate a complex json using script task

Hi,

I have a complex json object with which a camunda process starts(via postman). I need to validate the fields in this json object using javascript (script task). I couldn’t find any clue of how to start with. Any help regarding this please.

Thanks and Regards,
Madhuvanthi S

@Madhu Welcome to the Camunda forum :partying_face:

you can configure it similarly groovy script the javascript in script task to validate the JSON using SPIN feature.

image

Script Format: javascript
ScriptType: Inline script(you can provide the code in Script area while modeling) or External Resource(you can refer from classpath)
ResultVariable: you can store the result of validation in a variable.

Example SPIN api use in Script Task:

var carJson = execution.getVariableTyped("car").getValueSerialized();
var price = S(carJson ).prop("price").numberValue();
execution.setVariable("price", price);

Refer this:

2 Likes

@aravindhrs thank you for your response. I will surely try it.