ParseJSON
This function converts a JSON string into a Netcool/Impact Object.
Syntax
The
ParseJSON function
has the following syntax:result = ParseJSON(JSONString);Parameters
The ParseJSON function
has the following parameters.
Parameter |
Format |
Description |
|---|---|---|
|
String |
A formatted JSON String. |
Return value
The return of the function
can be accessed as an
Object.property format.items[index].fieldName
items[index].propertyArray[index].property
The return from the function is an Impact Object
representing the JSON string.
1) JSON Object is returned as Impact Object
2) JSON Array is returned as Array Of Impact Objects
3) Array returned as Java Array.Example
content="{"+
" \"glossary\": {"+
" \"title\": \"example glossary\","+
" \"GlossDiv\": {"+
" \"title\": \"S\","+
" \"GlossList\": {"+
" \"GlossEntry\": {"+
" \"ID\": \"SGML\","+
" \"SortAs\": \"SGML\","+
" \"GlossTerm\": \"Standard Generalized Markup Language\","+
" \"Acronym\": \"SGML\","+
" \"Abbrev\": \"ISO 8879:1986\","+
" \"GlossDef\": {"+
" \"para\": \"A meta-markup language, used to create markup languages"+
" such as DocBook.\","+
" \"GlossSeeAlso\": [\"GML\", \"XML\",1]"+
" },"+
" \"GlossSee\": \"markup\""+
" }"+
" }"+
" }"+
" }"+
"}";
jsonObj = ParseJSON(content);
Log("jsonObj: " + jsonObj);
GlossSeeAlsoArray=jsonObj.glossary.GlossDiv.GlossList;
GlossSeeAlsoArray=GlossSeeAlsoArray.GlossEntry.GlossDef.GlossSeeAlso;
Log(" GlossSeeAlsoArray : " + GlossSeeAlsoArray);
LenG=Length(GlossSeeAlsoArray);
indexG=0;
while(indexG < LenG) {
Log("GlossSeeAlsoArray["+indexG+"] = " + GlossSeeAlsoArray[indexG]);
indexG = indexG+1;
}The policy output is similar to the following example: October 15, 2014 9:12:31 AM EDT[PolicyLogger][TestExample][pool-3-thread-478]
Parser log: jsonObj: "Context"=(glossary="Context"=(title=example glossary,
GlossDiv="Context"=
(GlossList="Context"=(GlossEntry="Context"=(SortAs=SGML,
GlossDef="Context"=(GlossSeeAlso={GML, XML, 1},
para=A meta-markup language, used to create markup languages such as DocBook.),
GlossTerm=Standard Generalized Markup Language, GlossSee=markup, ID=SGML,
Acronym=SGML, Abbrev=ISO 8879:1986)), title=S)))
October 15, 2014 9:12:31 AM EDT[PolicyLogger][TestExample][pool-3-thread-478]
Parser log: GlossSeeAlsoArray : {GML, XML, 1}
October 15, 2014 9:12:31 AM EDT[PolicyLogger][TestExample][pool-3-thread-478]
Parser log: GlossSeeAlsoArray[0] = GML
October 15, 2014 9:12:31 AM EDT[PolicyLogger][TestExample][pool-3-thread-478]
Parser log: GlossSeeAlsoArray[1] = XML
October 15, 2014 9:12:31 AM EDT[PolicyLogger][TestExample][pool-3-thread-478]
Parser log: GlossSeeAlsoArray[2] = 1An example of a JSON string that is an array and starts with a square bracket is converted to an Impact object.
JSONArray='[ { "color": "red", "value": "#f00" },'+
'{ "color": "green", "value": "#0f0" },'+
'{ "color": "blue", "value": "#00f" },'+
'{ "color": "cyan", "value": "#0ff" },'+
'{ "color": "magenta", "value": "#f0f" },'+
'{ "color": "yellow", "value": "#ff0" },'+
'{ "color": "black", "value": "#000" }]';
parsed=ParseJSON(JSONArray);
Log(parsed.arrayItems[0].color);Policy output.
Parser log: red