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

How in my example in groovy (java) to automatically detect the json field type?

In my task, I process the incoming json and use the ResultSetReader to return the data as a dataset. All types must be written to "types". They are now defined like this: def types = list.find (). Values ​​() *. GetClass () *. SimpleName But there…
Ekz0
  • 63
  • 1
  • 8
0
votes
1 answer

Groovy: JSON Parsing

Seeing an interesting issue, not sure this is to do with parser or the way it suppose to parse. Any help is appreciated import groovy.json.JsonSlurper def dMatch =…
Sri
  • 3
  • 4
0
votes
1 answer

How do i parse a text file that has json and get array element

I am trying to parse a text file with json and get one of the element from jsonArray. Below is the json i am trying to parse [ { "ContainerConfig": { "Labels": { "commit-id": "abcdef123d", "author": "Jon" } } …
Jon Abraham
  • 851
  • 3
  • 14
  • 27
0
votes
1 answer

groovy.lang.missingMethodException when running code as a .jar

I have this code in groovy to parse a json file: File file = new File(configFile) def config = new JsonSlurper().parse(file) When I run it in Intellij it works just fine. I then build it to create a .jar then execute it in the terminal with: java…
flacoding
  • 145
  • 1
  • 12
0
votes
2 answers

Is there any way to list latest Nexus Artifacts in Jenkins?

I am using Acive Choice Reactive Parameter plugin to list down Nexus Artifacts. This is the groovy script which I'm currently using. import groovy.json.* def targetUrl =…
Janith
  • 217
  • 1
  • 6
  • 15
0
votes
2 answers

Remove a specific JSONObject from JSONArray in groovy

Say I have a JSON request payload like { "workflow": { "approvalStore": { "sessionInfo": { "user": "baduser" }, "guardType": "Transaction" } } } I get the value of user…
GopherGopher
  • 376
  • 1
  • 2
  • 16
0
votes
1 answer

JsonSlurper inconsistently parses Strings? Sometimes returns String, sometimes returns ArrayList?

"context A": { "name": "parent A", "operation": { "name": "op A", "convenienceType": { "descriptor": "View", "id": "view_id" } }, "context B": { "name": "child B", …
Sam Jones
  • 43
  • 5
0
votes
1 answer

Creating dynamic stages in jenkins pipeline fails on first loop execution?

This is the pipeline I have created for processing a json from an API. However when I run this it fails after the first loop. import groovy.json.JsonSlurper pipeline { agent none stages { stage('Query Pull Requests'){ steps{ …
Gayan Jayasingha
  • 752
  • 2
  • 17
  • 33
0
votes
1 answer

Process JSON to Fasta, convert Python code to Groovy

I have a config file that looks like this: { "codes": { "0004F--0004R": { "Forward code Name": "0004F", "Forward code Info": "xxxyyy4", "Rev code Name": "0004R", "Rev code Info": "xxxyyy3" …
DUDANF
  • 2,618
  • 1
  • 12
  • 42
0
votes
1 answer

JsonSlurper parsing String containing Json into unexpected format

From a separate system I get a String parameter "messageJson" whose content is in the form: {"agent1":"smith","agent2":"brown","agent3":{"agent3_1":"jones","agent3_2":"johnson"}} To use it in my program I parse it with JsonSlurper. def myJson =…
E.T.
  • 189
  • 4
  • 17
0
votes
1 answer

Using Junit assert on json array of elements fails on first element

I'm trying to use Katalon Studio for some webservice automation. I have been following this guide on how to parse returned Json body using jsonslurper. https://docs.katalon.com/katalon-studio/tutorials/parse_json_responses.html Everything is working…
Bratok17
  • 53
  • 10
0
votes
2 answers

Parse a JSON object with the value as JSON string array

I am trying to parse a JSON string which is of the following format {"edgeNodeRegistrationStatus": ["{\"CONFIRMED\":\"TRUE\"}"]} I have written a code to parse it. import groovy.json.JsonOutput import groovy.json.JsonSlurper def jsonSlurper = new…
Rana
  • 41
  • 8
0
votes
1 answer

How can I check the value in a key-value nested list?

I have created a REST web service. I have in the response, a nested list with 5 key-value associations in each list. I only want to check if each value has the right format (boolean, string or integer). So this is the nested list. {"marches": [ …
Félix Mensah
  • 53
  • 2
  • 16
0
votes
1 answer

In Web UI Testing, is it possible to get the JSON response?

I am very new to Katalon Studio and had just a beginner experience using Jmeter. I knew how to code JsonSlurper since I used it often when creating JMeter test scripts. So is it possible to use JsonSlurper in a web UI test case in Katalon Studio?…
Jeffrey Aquino
  • 71
  • 1
  • 2
  • 6
0
votes
1 answer

How to set value of Json inside array

I have the following JSON with in an array and when I try to set a value for this JSON, script passes but value isn't set: { "langauageCode": "en-US", "Test": [{ "_modificationTypeCode": "added", "allocationTypeCode": "3", …
syed naveed
  • 85
  • 2
  • 12
1 2 3
8 9