pre-processing JSON

set up the Data Adapter to do a GET JSON from a URI. works fine. Dataset and Query Dialog WebServiceQuery works fine. the problem is the web server returns

{
    "objects": {
        "Server::672": {
            "code": 0,
            "message": "",
            "class": "Server",
            "key": "672",
            "fields": {
                "name": "some_server_name",
                "description": "some_server_description",
            }
        },
        "Server::1719": {
            "code": 0,
            "message": "",
            "class": "Server",
            "key": "1719",
            "fields": {
                "name": "some_server_name",
                "description": "some_server_description",
            }
        },
    },
    "code": 0,
    "message": "Found: 2"
}

the problem here is that the 'string::integer" format in the response makes it impossible to set the root path under objects. is there a way in JSS to remove the '::integer' pattern so Server can be used for the root path?

dmoroney's picture
Joined: Feb 4 2019 - 10:25am
Last seen: 4 years 1 week ago

What is your desired output? Are you tied to using the Webservice Datasource?

narcism - 4 years 1 month ago

the preferred result would be as follows. the "::key" expression would be filtered out somehow. Server would be set as the root path for the report loop

{
    "objects": {
        "Server": {
            "code": 0,
            "message": "",
            "class": "Server",
            "key": "672",
            "fields": {
                "name": "some_server_name",
                "description": "some_server_description",
            }
        },
        "Server": {
            "code": 0,
            "message": "",
            "class": "Server",
            "key": "1719",
            "fields": {
                "name": "some_server_name",
                "description": "some_server_description",
            }
        },
    },
    "code": 0,
    "message": "Found: 2"
}

the application doing this is iTop v2.x from Combodo. Hopefully, I don't have to be tied to the Webservice Datasource for that application. Other datasource suggestions are welcome.

dmoroney - 4 years 1 month ago

I understand that you want to remove the "::key" part, but is the output of the report that you want to achieve?

narcism - 4 years 1 month ago
show 4 more...

here's the process in mind

Get Server Response currently recieves in the Fields tab

v objects

> Server::672

> Server::1719

code

message

I'd like for Get Server Response to receive or for some pre-processing thing to clean the JSON into

v objects

> Server

> Server

code

message

then I can right click on Server and Set as Root Path to appear as objects.Server.
I'd click on the Data Preview tab to confirm the data I need before moving on to composing the report

dmoroney - 4 years 1 month ago

Try using JSONQL instead of Webservice Query. Create a JSON file Data Adapter where you specify your JSON URL and check "Use the report JSON expression when filling the report". Then in your report Dataset and Query Dialog pick the adapter and chose "jsonql" as language. Then use this expression to query for fields: objects["Server::.*"]

narcism - 4 years 1 month ago

It works.

Create the JSON File adapter

- File/URL: the web service URI including the trailing ?

- Left URL Parameters tab empty

- Entered the needed POST Parameters. A big thing here was to overtly set the desired output fields in the json_data payload

- Entered the needed Http Headers

- Select Use the report JSON expression when filling the report

- Tested the Connection and got Successful

- Save the adapter

Create a New Report. Data Adaper is the JSON File adapter created earlier. Click Next and click OK to continue, and Finish

- Open the DataSet and Query Editor. Select Language jsonql

- Entered this expression 'objects["Server::.*"]fields' (without the ' quotes) as the Set record node (generate query)

- Clicked on Read Fields and the Fields tab filled in

- Clicked on the Data Preview tab and Refresh Preview Data. It's all there

Thanks for the suggestion.

dmoroney - 4 years 1 month ago
dmoroney - 4 years 1 month ago

0 Answers:

No answers yet
Feedback