Petr_Panuska Absent Member.
Absent Member.
2989 views

How to work with JSON in OO

Hello,

in my OO flows I need to process XML as well as JSON documents.

While I found and I'm using the powerful XPath and XSL Transformation on XML files, I did not find any similarly powerful solution for JSON documents in OO.

 

Is there some JSON alternative to XPath or XQuery? Like JSONPath?

 

Thanks,

Petr Panuska

Labels (1)
0 Likes
3 Replies
Absent Member.. Frisendal Absent Member..
Absent Member..

Re: How to work with JSON in OO

Hi Petr 

 

The alternative is indeed JSONPath. And you can easily make this work yourself in a few steps:

  1. Copy the Do Nothing operation to your own project and call it something like "JSONPath Query"
  2. Delete the inputs (if there are any) and create two new required inputs: "jsonString", "jsonPathExpr"
  3. Copy the JS code found via: http://goessner.net/articles/JsonPath/ to the scriptlet part of your new operation.
  4. Then add these lines to the end of the scriptlet:
    scriptletResponse = "success";
    scriptletResult = jsonPath(JSON.parse(jsonString),jsonPathExpr);
  5. You can also add a bit of code for changing the response if the search is unsuccessful etc. 

 

We are considering adding this type of functionality in future version of OO.

 

HTH,

Emil

 

HP Software OO RnD, Community Assistance Team, https://hpln.hp.com/group/operations-orchestration
Absent Member.. jramboz Absent Member..
Absent Member..

Re: How to work with JSON in OO

Hi Emil

 

I am in OO 9.07

I tried the scriplet and I got an error :

 

                           ReferenceError: "JSON" is not defined

 

Is it possible to download and add JSON to OO ?

Thank you

 

Jacques

0 Likes
Absent Member.. Steve_Drummond Absent Member..
Absent Member..

Re: How to work with JSON in OO

Hi Jacques,

 

If you look at the scriptlet code of an operation in [/Library/Utility Operations/Containers/JSON] you will see a one-liner piece of code that defines the "JSON" object that Emil is referencing.

 

Copy that code into your jsonPath scriptlet before attempting to use the JSON object.

 

cheers

steve

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.