How to access response JSON Data Element

I’m working with the HTTP Connector Task and I have an output variable with the following code;

var json = S(connector.getVariable("response"));
json

I’m trying to figure out how to put the returned data into variables.

So for example, let’s say the response is the following JSON;

{
  "test": {
    "id": "1"
  }
}

Would I put the id value to a variable like this?

var res = connector.getVariable("response");
var json = S(res);
json.prop("id").value();

I’m thinking this will not work but I’m not sure how to address the child id data element.

Can anyone help me out?

Toodaloos :slight_smile:

If your connector returned the response Json wrapped in the S() then you don’t need to use S() again when retrieving the response.

You can just do execution.getVariable(“myResponse”).prop("propName).value()

1 Like

Ahhh, thanks so much for your help @StephenOTT

So for my specific JSON example which includes a child element above would this be correct?

execution.getVariable(“myResponse”).prop("id").value()

or would it be;

execution.getVariable(“myResponse”).prop("test").prop("id").value()

The second one.

See docs Reading JSON | docs.camunda.org

When you are using the S() you are saving your response Json string as a spin object / Java object. When you do getVariable it is returning the Json as the Java object and thus you don’t need to do the S() again

1 Like

Great, I’ll check out that section of the documentation.

Thank you for your time sweetie!