---
title: "Working with JSON Data"
canonical: "https://support.appfire.com/space/SUPPORT/80878453/Working%20with%20JSON%20Data"
format: markdown
---
As happens from time to time, you will want to work with JSON data. For example, when passing JSON data when using httpPut() or httpPost().

## Background

In this example, I will be using the [this REST API example](https://community.atlassian.com/t5/Jira-Service-Management/REST-API-update-Comment-to-internal/qaq-p/1483037) from the Atlassian Community.

## Method 1 - Add JSON Data Inline

As is shown in the example, we start with the example JSON that will be used to input.

|  |
| --- |
| ```
"properties": [
   {
    "key": "sd.public.comment",
    "value": {
       "internal": true
    }
   }
  ]
}
``` |

## Overview

1. Use the Find/Replace feature of the SIL Manager to add an escape character before every quote.
2. Surround each line with quotes and place a plus sign at the end.
3. Set the newly formatted JSON to a string variable and put a semicolon at the end.

## Step 1 - Add an Escape Character before Every Quote

Use the Find/Replace feature of the SIL Manager to add an escape character before every quote.

![image](media://e5f80165-7d02-4c1b-b2d8-21ed7cc02c7d)

## Step 2 - Place Quotes Around Each Line

Surround each line with quotes and place a plus sign at the end. Place a semicolon at the end.

![image](media://a1c59f47-bef6-4a0a-9b86-16c249d588e2)

## Step 3 - Set the Formatted JSON to a String Variable

Set the entire code block to a string variable so that it can be passed into the REST endpoint.

|  |
| --- |
| ```
string updateInfo = "{" +
                        "\"properties\": [" +
                            "{" +
                                "\"key\": \"sd.public.comment\"," +
                                "\"value\": {" +
                                    "\"internal\": true" +
                                "}" +
                            "}" +
                        "]" +
                    "}";
                     
runnerLog(updateInfo);
``` |


## Step 4 - Print Output and Check for Accuracy

The output should match the original JSON from the beginning.

![image](media://36cbb52f-122b-4396-b1ff-c4fc36f7dbbb)

## Step 5 - Change Desired Hard-Coded Values to Accept Variables

Add a variable and use plus signs to concatenate it to the existing string values. Again, the output should match the original JSON from the beginning.

![image](media://dc39c323-6874-4f74-8a2f-2b5582580f54)

## The Final Script

Below we use [httpPut()](https://appfire.atlassian.net/wiki/spaces/SIL/pages/16518381) to pass the "updateInfo" values to update the Service Desk value "isPublic" to false.

|  |
| --- |
| ```
string isPublic = "false";
number [] ids = getAllCommentIds(key);
number lastComment = ids[size(ids) -1];
 
 
string updateInfo = "{" +
                        "\"properties\": [" +
                        "{" +
                        "\"key\": \"sd.public.comment\"," +
                        "\"value\": {" +
                            "\"internal\": " + isPublic + "" +
                        "}" +
                        "}" +
                        "]" +
                    "}";
 
 
HttpRequest request; 
request.headers += httpCreateHeader("Content-Type", "application/json"); 
request.headers += httpBasicAuthHeader("admin", "admin");  
 
string result = httpPut("http://localhost:8080/rest/api/3/issue/" + key + "/comment/" + lastComment, request, updateInfo);
 
// runnerLog(result);
 
number statusCode = httpGetStatusCode();
if (statusCode >= 200 && statusCode < 300) {
    runnerLog("SUCCESS");
}
else {
    string msg = trim(statusCode) + ":" + httpGetErrorMessage() + ":" + httpGetReasonPhrase();
    runnerLog(msg);
}
``` |

## Additional Help

Need help implementing this script? Talk to me directly to me by clicking on the bot on this page.

## Related articles



> Macro (contentbylabel)

> Macro (details)
> 
> | Related issues |  |
> | --- | --- |