How to set nested JSON string parameters? [using setStringParameter()]

Jamison Cote2
Mega Expert

I am attempting to populate a nested JSON object via JavaScript.

I'm pretty comfortable with setting up JSON Parameters that are not nested.

r.setStringParameter('field_name', value);

{
"field_name":"value"
}

But how would I set up my scripted REST call to populate the following nested values:

{
"fields": {
"project":
{
"key": "How do I set this?" // This value
},
"summary": "How do I set this?",
"description": "How do I set this?",
"issuetype": {
"id": "How do I set this?"
}
}
}

In the above example, how would I populate "key"?

Setting r.setStringParameter() of all the following have failed:

r.setStringParameter(fields.project.key, 'value');

r.setStringParameter(key, 'value');

Is the JSON Content field on the REST Message itself the only way to go about doing this? What happens if I set a string parameter via script but I have a JSON attribute hard coded?

Thanks!

1 ACCEPTED SOLUTION

dvp
Mega Sage
Mega Sage

Here is how you can pass the object

 

var obj = {};
obj.key = 'value';

r.setStringParameter('project', obj);

View solution in original post

2 REPLIES 2

SanjivMeher
Kilo Patron
Kilo Patron

You can do that by

 

var myJSON = {
};
myJSON.fields.project.key ="How do I set this?";

 

mySoap.setRequestBody(JSON.stringify(myJSON));


Please mark this response as correct or helpful if it assisted you with your question.

dvp
Mega Sage
Mega Sage

Here is how you can pass the object

 

var obj = {};
obj.key = 'value';

r.setStringParameter('project', obj);