---
title: "Working with JSON Data"
canonical: "https://support.appfire.com/space/PSJ/15481741/Working%20with%20JSON%20Data"
format: markdown
---
> Macro (aura-html)


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://b4528053-324c-4a04-9f58-cb62d2be70db)

## 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://d978d0ae-7204-4d1e-a83a-5ca835bcf421)

## 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://a676e810-c7f7-4faa-8613-7906740c86ca)

## 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://f74c2d1c-becb-485d-8dee-985371d4e5e3)

## The Final Script

Below we use [httpPut()](https://appfire.atlassian.net/wiki/spaces/PSJ/pages/15489919) 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 |  |
> | --- | --- |