---
title: "Working with JSON Data"
canonical: "https://support.appfire.com/space/PSJC/491002067/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.

![Power Scripts for Jira Cloud JSON accuracy validation demonstration](media://711a9f31-58d1-4c3a-8f4c-13a4e083e87f)

## 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.

![Power Scripts for Jira Cloud JSON value replacement demonstration](media://674ff38a-bbc1-4068-9f41-220e2f299668)

## 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.

![Power Scripts for Jira Cloud postfunction configuration interface](media://04d48c12-440c-45f5-9e9a-a7cb16ad4716)

## 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.

![Power Scripts for Jira Cloud WSJF scripted field configuration](media://2b2d78b9-b2e4-4e54-b418-261e99f65827)

## The Final Script

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