Questions tagged [jsonslurper]

JsonSlurper is a Groovy class that makes parsing and working with JSON simpler than with Java.

JSON slurper which parses text or reader content into a data structure of lists and maps.

Example usage:

 def slurper = new JsonSlurper()
 def result = slurper.parseText('{"person":{"name":"Guillaume","age":33,"pets":["dog","cat"]}}')

 assert result.person.name == "Guillaume"
 assert result.person.age == 33
 assert result.person.pets.size() == 2
 assert result.person.pets[0] == "dog"
 assert result.person.pets[1] == "cat"

For more info see the docs.

123 questions
0
votes
1 answer

Groovy - JSONSlurper parsing json

I have problem with my SoapUI Groovy script. I have following json (simplified): { "data":{ "XXX":[...] "YYY":[...] }, "next":"ffawef234fava23r" } I have values of XXX and YYY in my previously TestStep as request parameters and I extract…
jadupl
  • 210
  • 6
  • 17
0
votes
0 answers

Resource Efficient Parsing of JSON in Groovy

I have a program that interfaces with an API which outputs JSON responses. Considering I want to extract some specific keys and values from the JSON to use in my program, but at a later point I may want to expand on this, what is the most resource…
Donglecow
  • 507
  • 4
  • 22
0
votes
3 answers

How to use JSONSlurper to perform assertion on JSON array response in groovy

I'm trying to write extract the name value "Acura" from a JSON array response by using the location of the value stored in a variable called "jsonFieldName". Below is the code that I'm trying to do this with, however, everytime i run the script,…
fambo
  • 173
  • 1
  • 2
  • 13
0
votes
3 answers

How to extract JSON parameter using JsonSlurper in Groovy

I've written the following groovy script in SOAPUI to execute an assertion on a JSON response. I'm having difficulty writing the assertion to extract and assert on Weather > main > Clouds property and value of the JSON response. Can someone please…
fambo
  • 173
  • 1
  • 2
  • 13
0
votes
1 answer

Grails 1.3.9 parse JSON file

I am working on a project with Grails 1.3.9 and I need to parse a JSON file and read some values. This can be easily done with JsonSlurper but it is supported only for Grails 1.8 and higher. Are there any other techniques to achieve this?
Jacob
  • 3,580
  • 22
  • 82
  • 146
0
votes
1 answer

How to Parse a JsonSluper object?

I have the following JsonSluper object : [ [id:5017,feature:age,value:20], [id:2017,feature:city,value:paris], [id:3017,feature:country,value:france] ] and I want to get the following JsonObject: "person":{ "age":20, "city":paris, …
Aissa El Ouafi
  • 157
  • 1
  • 4
  • 14
0
votes
1 answer

JsonSlurper float precision issue

I have a file with some data and configuration parameters that i need to change before I use it as body data for POST rest call. So I am using slurper to get the configuration value JsonSlurper slurper = new JsonSlurper() def inputFile = new…
user2847238
  • 169
  • 3
  • 14
0
votes
1 answer

How to change the value (and type) of a jsonslurped lazymap entry

I have the following JSON: {"name":"Guillaume","age":33,"address":"main st","pets":[{"type":"dog", "color":"brown"},{"type":"dog", "color":"brown"}]}} I have used JsonSlurper to parse it. I have a need to be able to modify the contents of the JSON…
vjanzaldi
  • 1
  • 1
0
votes
1 answer

Convert WebService Response into Json Arrary and Jsobobject using Groovy

I am testing RESTful webservice using SoapUI. We use Groovy for that. I am using jsonslurper to parse the response as Object type. Our reponse is similar to this: { "language":[ { "result":"PASS", …
user3055964
  • 130
  • 2
  • 11
0
votes
2 answers

Groovy / jsonSlurper using OR (IN) in assertion

//verify if successful transaction assert jsonSlurper.body.message == "Approved" I want this to be True for either "Approved" and "Aprobada" and this doesn't work: assert jsonSlurper.body.message IN ("Approved","Aprobada") Thanks
QB1979
  • 123
  • 1
  • 8
0
votes
2 answers

How to parse Json response and truncate child nodes

This is the JSON response I am trying to parse: { "data": { "Content": { "id": 26, "name": "Dashboard1" }, "List": [ { "ListContent": { "id": 178, "name": "Card-144" …
Dighate
  • 91
  • 1
  • 13
0
votes
0 answers

Using Groovy JsonSlurper with Reader in Jenkins causing IllegalArgumentException

I have the following code that I'm executing from a Jenkins non-System Groovy Script using Groovy 2.4.3 private void readJsonFile() { if (testsValid == false) { def jsonSlurper = new JsonSlurper() try { …
0
votes
1 answer

JSONException error Grails

Paring JSON file, using JsonSlurper My code is like below String url = 'https://urlThatIWantToGoto' String jsonFile = new JsonSlurper.parseText(new URL(url).text)) JSONArray jsonParse = new JSONArray(jsonFile) Whenever I run this code, I get a…
Tinolover
  • 166
  • 1
  • 5
  • 19
-1
votes
1 answer

Groovy: Correct invalid JSON as per XML specifications

I am trying to correct the Incoming JSON as I have a JSON to XML converter. I wish to replace the leading number in a field etc 1Doc1 to S_Doc1 etc. Also I Need to replace the invalid XML element names from JSON such as Slash etc. Here is my Code…
Tppi
  • 3
  • 5
-1
votes
1 answer

Accessing and looping though nested Json in Groovy

so I have been stuck with this problem for quite some time now. I'm working with some data provided as JSON and retrieved via WSLITE using groovy. So far handling the json structur and finding data was no problem since the webservice response…
Christoph Zabinski
  • 327
  • 2
  • 5
  • 17
1 2 3
8
9