Micro Focus Expert
Micro Focus Expert
79 views

(OO) Support Tip : Nested JSON Manipulation

If it is necessary to modify nested JSON values string manipulation will need to be done.
This can be accomplished many ways and may need multiple manipulations depending on the complexity of the object.

Example:
{
  "powertrain":
      {"nismasterserver":"abc001",
       "nisdomain":"ptrain"},
  "toluca":
      {"masterserver":"def01",
       "domain":"toluca"}
}

 

 

Desired:
To add to the powertrain key key/value pairs of homeserver:xxx and name:yyy

1. Get Value from Object
Inputs:
  object= JSON in example above
  key = powertrain

2. Create a filter to modify the output to the desired value.

Value returned: {"masterserver":"abc001", "nisdomain":"ptrain"} and then filtered it to replace the last } and add the extra JSON value pairs

New Value
{"masterserver":"abc001", "nisdomain":"ptrain",”homeserver”:”xxx”,”name”:”yyy”}

3. Add JSON Property to Object
Inputs:
jsonObject = JSON from example above
newPropertyName = powertrain
newPropertyValue = Result after filtering in step 2.

New JSON
{
  "powertrain":
      {"masterserver":"abc001",
       "domain":"ptrain",
       “homeserver”:”xxx”,
       “name”:”yyy”},
  "toluca--domain--com":
      {"masterserver":"def01",
       "domain":"toluca"}
}

 

More information can be found at:

https://softwaresupport.hp.com/group/softwaresupport/search-result/-/facetsearch/document/KM01883041

Labels (2)
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.