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
1
vote
2 answers

How to list json field names and values?

Please help me figure out the problem. I program in groovy (you can use a java example, it looks like there). Json comes to the input, in which it is not known how many fields. There can be 5 fields, maybe 10, maybe 50. My task is to process this…
Ekz0
  • 63
  • 1
  • 8
1
vote
1 answer

Iterate through JSONObject

I am working on writing a groovy script now and I am absolute new in groovy lang. I have Json Object, like that: { "firstVar": { "active": "false", "title": "First Var" }, "secondVar": { "active": "false", …
kairatawer
  • 53
  • 8
1
vote
1 answer

Groovy JSON is missing quotes around strings

(Groovy Version: 2.4.16 JVM: 11.0.8 Vendor: Debian OS: Linux) My bash shell script outputs a JSON string that looks like this (without the "sout: "): sout: {"vms":["Jenkins","UbuntuRunner"]} Which I use as input to this Groovy code: def sout =…
Kenny Cason
  • 497
  • 5
  • 17
1
vote
1 answer

How to get relative path using Groovy Gpath in json?

I am using rest assured with Serenity BDD and using Groovy Gpath to navigate thru JSON. Now, I have a scenario like where I need to get the Cost values more than 2 with below JSON. is there any way to use a relative path to navigate using GPath with…
1
vote
1 answer

JsonSlurper parseText exception in Groovy Script: java.lang.ClassCastException: [B cannot be cast to [C

I want to parse Json in Groovy, but it throwns exception, don't known what's wrong with my code, need some help [ENV:] jdk-9.0.4 ide:idea lang:Groovy Exception as below: WARNING: An illegal reflective access operation has occurred WARNING: Illegal…
Silence He
  • 69
  • 10
1
vote
0 answers

Groovy Output XML sourcing from JSON

I'm struggling with getting a groovy script to output what I need adhering to a vendor spec. Eventually, I will populate JsonSlurper with a file rather than static rows, but for simplicity I've provided sample JSON. When running the following code…
1
vote
1 answer

Parsing json in json Groovy Katalon Studio

I got a JSON text which I should parse, but for some reason I can't parse it because it has another array inside. My JSON looks like that: { "statementId": "1", "movements": [ { "id": 65, "date": "2019-02-05", …
brithwulf
  • 538
  • 10
  • 35
1
vote
1 answer

Mapping custom strings found in JSON to POGO enum cases

In the context of a Grails application, we parse JSON into command objects. The automatic conversion from a JSON map to the POGO fails with an error like this: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object…
Raphael
  • 9,779
  • 5
  • 63
  • 94
1
vote
1 answer

Parsing child nodes of JSON response in SOAP UI using groovy json slurper

I am getting a JSON response from an webservice like below . I want to parse all childs of results node using Groovy Json slurper and assert the value is correct. { "status": "Healthy", "results": [ { "name":…
Priyanka Ray
  • 85
  • 2
  • 9
1
vote
1 answer

How to split an array of JSON documents into fixed size chunks?

I have a JSON document representing an array of 100 objects and I need to process this document in batches, e.g. 10 objects per batch. def text = '[{1st},{2nd},{3rd},{4th},...{100th}]' def json = new groovy.json.JsonSlurper().parseText(text) Now I…
Mister X
  • 3,406
  • 3
  • 31
  • 72
1
vote
1 answer

Parsing JSON object in Groovy

Im Trying to write a Groovy script which performs a REST api call and gets an JSON object, then, i need to get a specific string out of this JSON and check if it matches another string that i provides in the script. i did everything until the…
Oz Giat
  • 127
  • 3
  • 10
1
vote
2 answers

Number Format Exception in Groovy

I am trying to compare the Sales Tax Rate of 6.75 against my expected value of 6.75 which is in string format. I wrote the below lines of Groovy code to achieve this, but I am getting Number Format Exception and I could not figure out where the…
Srinivasan Ramu
  • 1,033
  • 4
  • 11
  • 23
1
vote
2 answers

How to get key from ArrayList nested in JSON using Groovy and change its value

I need to be able to find the key quote.orderAttributes[0].attributeDetail.name and set its value to null or any other value I want. I only need to do this for the first element in any list so selecting [0] is fine. I want to be able to use a path…
SleepyD
  • 39
  • 1
  • 2
  • 9
1
vote
1 answer

How to deal with spaces in JSON Key?

I have a string of JSON that I've retrieved from an API. I'm using JsonSlurper to parse the string into JSON, but I'm unsure how to handle when the key contains spaces. An example of the JSON is: { "total": 3, "page": 1, "totalPages": 1, …
Donglecow
  • 507
  • 4
  • 22
1
vote
2 answers

Groovy-JSONSlurper: Transform JSON map into a key=value pair

I have a JSON object, which we assume to be flat (no nesting) and a map. How can I transform this into a single string of key=value pairs, delimited by tab using JSONSlurper in Groovy?
oikonomiyaki
  • 7,691
  • 15
  • 62
  • 101
1 2
3
8 9