Previous Topic: JSON ParsingNext Topic: REST Methods


ca_pam_convertJSONToJSObject(jsonString)

Use this method to create a JavaScript object from a JSON string. The ca_pam_convertJSONToJSObject method supports quotation marks notation. Quotation marks notation is an alternate way to access any property from a JavaScript object when the property name is not a valid JavaScript identifier. For example, to access the id property from the book object, quotation marks notation syntax is book[“id”].

Input Parameters
jsonString (string)

Defines the JSON string to convert to a JavaScript object.

Return Value

Returns the JavaScript object.

Example

The example shows a JSON string:

{"menu": {
  "id": "file",
  "value": "File",
  "popup": {
    "menuitem": [
      {"value": "New", "onclick": "CreateNewDoc()"},
      {"value": "Open", "onclick": "OpenDoc()"},
      {"value": "Close", "onclick": "CloseDoc()"}
    ]
  }
}}

The following sample script accesses the id field value:

var parsedJSON = ca_pam_convertJSONToJSObject(jsonString);
var menuObj = parsedJSON.menu.;
var idValue = menuObj.id.;

The following sample script accesses the onclick element in the second element of the menuitem array:

var parsedJSON = ca_pam_convertJSONToJSObject(jsonString);
var menuObj = parsedJSON.menu;
var popUpObj = menuObj .popup;
var menuItemArray = popUpObj .menuitem.;
var secondElementOfMenuItemArray = menuItemArray[1];
var onclickElement = secondElementOfMenuItemArray.onclick;

You can also find this function in the out-of-the-box content in CA Process Automation.

  1. On the Home page, click Browse Out-of-the-Box Content.
  2. Navigate to the User Interaction Forms folder, then 07 Populate Table RESTful WS: Populate Table RESTful WS.