

Now we will make use of the JSONPath queries to search for the item var srchItem = search result is going to have more than one values then you need to make use of the SelectTokens()method. Next up is to parse the json string to an array using the JArray.Parse() method. Then import the namespace to your class using the below statement. įirst you need to add the JSON.NET package to your project via NuGet.

So I did some research on this topic and finally resolved it using the SelectTokenmethod available in JSON.NET. Also, I didn't wanted to create a new class to bind these elements because I just needed to find whether this string has value for a particular key and return the object if found. I can use the combination of a foreach loop and condition check to retrieve the item, but I didn't want to use that because I felt that it's not the proper way to do it. It was an array of items which has got two keys named Nameand Country and I want to return the object if the search criteria is matched. I was working with JSON string like the one given below. # creating a JSON String with an array (directly executed via Run Automation Script button) from I hit a roadblock in parsing and finding an element in a JArray object in one of the projects which I was working at my workplace. Below, you can see the code piece for this task: The second exercise is more interesting since we will use both JSONObject and JSONArray in order to send a parent record together with its two child records. The Output of Code 1 in Script Results Window of Automation Scripts application is as follows: # creating a JSON String (directly executed via Run Automation Script button) from import JSONObjectįrom sys import * # method for creating a JSON formatted String def createJSONstring():Ĭode 1 - Creating a JSON Formatted String You can see the example code piece below. For clarification, The JSON body holds data from Maximo objects which will be sent to the external system to create associated records there.įor single objects we use JSONObject alone which is an easy task. I needed to send a JSON formatted text as the body of an http POST request.

My starting point for this exercise was the requirement of a REST client implemented on Maximo for an external REST service. More information on JSON and JSON4J library can be found via the link below: Maximo framework includes json4j.jar library for JSON implementations such as constructing JSON formatted data, XML to JSON conversions, JSON string and stream parsing etc.
