Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Unable to parse the JSON data

rudra1
Tera Expert

Hi All,

Unable to parse the JSON data  which i am getting like as below: i want to map the highlighted ones. Please advice.

{
  "Incident" : {
    "properties(description)" : {
      "value" : "Service Account, Logic Monitor made an attempt to run commands remotely on ******S002 from *****789, using 1 PowerShell command. "
    },
    "properties(owner(userPrincipalName))" : {
      "value" : "example 123"
    },
    "properties(title)" : {
      "value" : "Remote code execution attempt"
    },

},

"HostEntity" : {
    "properties(hostName)" : {
      "value" : "8888S002, 9999S001"
    },
    "properties(additionalData(ShouldResolveIp))" : {
      "value" : "False, False, False, False, False"
    }

},

1 ACCEPTED SOLUTION

Try this code below

var str = {
   "Incident":{
      "properties(description)":{
         "value":"Service Account, Logic Monitor made an attempt to run commands remotely on ******S002 from *****789, using 1 PowerShell command. "
      },
      "properties(owner(userPrincipalName))":{
         "value":"example 123"
      },
      "properties(title)":{
         "value":"Remote code execution attempt"
      }
   },
   "HostEntity":{
      "properties(hostName)":{
         "value":"8888S002, 9999S001"
      },
      "properties(additionalData(ShouldResolveIp))":{
         "value":"False, False, False, False, False"
      }
   }
};

       
        var str2 = str.Incident;
        gs.print(JSON.stringify(str2["properties(description)"].value));//-- -- -- -- -- -- - > printing the value as Undefined

Thanks & Regards,
Vasanth

View solution in original post

13 REPLIES 13

it worked. Thank you @Vasantharajan N for help.

gs.print(JSON.stringify(str2["properties(description)"].value));

.value worked 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Is that a valid json string?

Did you check that?

regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I am getting this data when integrating with one of the tool through plugins.

Hi,

are you sure that's the complete json response you are getting because the json is invalid

I checked here

Share the complete script which you are using to invoke the API

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Here is the JSON format @Ankur Bawiskar .

{"Incident": {
  "properties(description)": {
    "value": "Service Account, Logic Monitor made an attempt to run commands remotely on ****, using 1 PowerShell command. "
  },
  "properties(owner(userPrincipalName))": {
    "value": ""
  },
  "properties(title)": {
    "value": "Remote code execution attempt"
  },
  "properties(owner(email))": {
    "value": ""
  },
  "properties(owner(assignedTo))": {
    "value": ""
  },
  "type": {
    "value": "Example123"
  },
  "properties(additionalData(bookmarksCount))": {
    "value": 0
  },
  "properties(incidentUrl)": {
    "value": "TestURL"
  },
  "properties(status)": {
    "value": "New"
  },
  "properties(lastModifiedTimeUtc)": {
    "value": "2022-**-** 05:46:54 UTC"
  },
  "properties(firstActivityTimeUtc)": {
    "value": "2022-**-** 15:30:27 UTC"
  },
  "properties(additionalData(alertsCount))": {
    "value": 1
  },
  "properties(additionalData(alertProductNames))": {
    "value": "Test 9876"
  },
  "properties(createdTimeUtc)": {
    "value": "2022-00-00 15:38:01 UTC"
  },
  "name": {
    "value": "*****-****-***-***-******"
  },
  "properties(severity)": {
    "value": "Medium"
  },
  "properties(additionalData(commentsCount))": {
    "value": 0
  },
  "properties(owner(objectId))": {
    "value": ""
  },
  "etag": {
    "value": "\"0000000000\""
  },
  "properties(lastActivityTimeUtc)": {
    "value": "2022-00-00 15:38:01 UTC"
  },
  "properties(incidentNumber)": {
    "value": 39
  },
  "properties(additionalData(tactics))": {
    "value": "Execution"
  },
  "properties(relatedAnalyticRuleIds)": {
    "value": "********"
  },
  "id": {
    "value": "Test Related Analytics"
  }
},
"HostEntity": {
  "properties(hostName)": {
    "value": "EUTest**, EUE***000"
  },
  "properties(additionalData(ShouldResolveIp))": {
    "value": "False, False, False, False, False"
  },
  "kind": {
    "value": "Test"
  },
  "properties(dnsDomain)": {
    "value": "Test Domain"
  },
  "properties(friendlyName)": {
    "value": "EUTest**, EUE***000"
  },
  "name": {
    "value": "7478"
  },
  "id": {
    "value": "478"
  },
  "type": {
    "value": "Test Value"
  }
}