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

Kieran Anson
Kilo Patron

What have you done already to attempt to parse the provided JSON payload? Is this using Flow Designer and a parse JSON action or are you using a script? If the latter, can you provide your existing logic so any member of the community that responds doesn't duplicate on a solution you've already tried.

rudra1
Tera Expert

I have storing the string data in variable str.

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 obj =JSON.parse(str);
gs.print(JSON.stringify(obj.Incident));
var str2 = obj.Incident;
gs.print(JSON.stringify(str2.properties(description))); ------------->printing the value as Undefined

@Ankur Bawiskar  any help ?

End the str with a semi colon and try

 

 

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