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
1 answer

Get value of variable from json using jsonslurper

I have the following JSON code: { "TIMESTAMP":"2017-05-26-20.22.40.016000", "dateTime":"2017-05-26H-20.22.4", "AMUCCY1":"ADP", "rates":[ { "AMUCCY2":"AED", "AMURAT":"1.000000000", "AMUNXRT":0 }, { …
Harold Decapia
  • 375
  • 1
  • 8
  • 23
1
vote
1 answer

Using JSONSlurper to pass second level of JSON in list

I am using Groovy and JSON Slurper in one of my Jenkins plugins. Below is the code I am using: import groovy.json.JsonSlurper def inputFile = new File('.\\TestSuitesJ.json') def inputJSON = new JsonSlurper().parse(inputFile) def keys =…
NewWorld
  • 764
  • 1
  • 10
  • 31
1
vote
1 answer

Recursively extracting JSON field values in Groovy

I need to implement a method that will scan a string of JSON for a particular targetField and either return the value of that field (if it exists), or null (if it doesn't): // Ex: extractFieldValue(/{ "fizz" : "buzz" }/, 'fizz') => 'buzz' // Ex:…
smeeb
  • 27,777
  • 57
  • 250
  • 447
1
vote
2 answers

JsonSlurper avoid trimming last zero in a string

I am using JsonSlurper in groovy to convert a json text to a map. def slurper = new JsonSlurper(); def parsedInput = slurper.parseText("{amount=10.00}"); Result is [amount:10.0] I need result without trimming last zero. Like [amount:10.00] Have…
Raghav
  • 81
  • 1
  • 5
0
votes
1 answer

Groovy script-Issue while accessing 3rd level child from JSON file

I need help to access these nodes from given JSON: ( all the values which are true or false) billingAddress shippingAddress duplicate { "active": "true", "groups": { "uid": "zzzz", "integrationKey": " " }, "name":…
pooj
  • 1
  • 1
0
votes
2 answers

Jenkins Error - java.io.NotSerializableException: groovy.json.JsonSlurperClassic

I am using Groovy trying to do an API call in a Jenkinsfile and trying to get a JSON response back. Here’s my code: def url = “some url link” def connection = new URL(url).openConnection() jsonSlurper = new…
0
votes
1 answer

jmeter - How I can iterate a json response to get all the keys and related value

there is a way to get all keys and related values of a json? I don't know the fields in output, then I can't use json extractor. I've found this code, but it returns only the keys: import groovy.json.JsonSlurper def traverse traverse = { tree, keys…
sarjaana
  • 77
  • 1
  • 1
  • 6
0
votes
0 answers

Jenkins dynamic user input using JsonSlurper throwing error

I'm trying to create a dynamic Jenkins pipeline where users can target a cloud container registry and list the tags of a particular image in drop down menu on Jenkins console to deploy it further in selected environments. For this, I came across an…
0
votes
1 answer

Obtaining a random value using Groovy JsonSlurper

I'm new to Groovy and trying to understand the best way of approaching this. Apologies for an elementary question. Given a Json file vehicles.json of: { "prod": [ { "id": "CAR LARGE", "vehicle": "102920", "name": "BMW 325" …
Steerpike
  • 1,712
  • 6
  • 38
  • 71
0
votes
1 answer

modifying Json with Json Slurper in groovy

I have a scenario where i need to remove one object inside my Json string in groovy. below is the structure of my json. I need to remove "eventLogs" part from my Json. { "_id":"123456", "type": "prod", "metaData" :{...}, "isUpdated": true, …
deewreck
  • 113
  • 7
0
votes
1 answer

Groovy JSONSlurper to reformat JSON object into array

I've been spinning my wheels long enough on this so I'm hopeful for some help or pointers. I'm new to groovy and have been able to wade my way this far in, but am stuck here. Using Groovy, given the following input JSON: { "rates": { …
dawgPdx
  • 1
  • 2
0
votes
1 answer

Using parsed json by JsonSlurper, how do I return a value based on another key value pair of the same node?

I have below JSON and want to fetch the value of "person1" and "person2" either into a map as a key-value pair or individually is also fine. Expected Output: [attributes:["person1": "ROBERT", "person2": "STEVEN"]] I started with JSON parsing and…
user1523153
  • 139
  • 3
  • 10
0
votes
1 answer

JsonSluper and JsonOutput convert some symbols in string to strange characters

I am using a groovy script to convert some of the values in the body to their primitive datatype. To achieve this I am using JsonSluper and JsonOutput. JsonSluper and JsonOutput are converting some symbols in string from my json body to strange…
sravan kumar
  • 583
  • 3
  • 11
  • 24
0
votes
1 answer

Jmeter - How to get nested object in json with multiple object

I have this json: { "deviceId": "deviceCustom", "moduleId": "custom", "properties": { "desired": { "settings": { "ef78c18c-2291-4d15-ae87-d89abb9b1fef": { "name": "elements", …
sarjaana
  • 77
  • 1
  • 1
  • 6
0
votes
1 answer

IllegalArgumentException error when getting the null response from Json

I am using Groovy for creating an automation script for parsing the response data from api and updating in my excel test data file. It is working correctly but for certain data there is no response from api so it throws the…
1 2 3
8 9