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

Get the id of a parent element by a sub-child value of Json response using groovy

I have following groovy script to get the values from the response. import com.eviware.soapui.support.XmlHolder import groovy.json.JsonSlurper def response = context.expand( '${GetLoansList#Response}' ).toString() log.info(response) def slurper…
Wicky
  • 118
  • 2
  • 13
0
votes
2 answers

How can I sort a multi-level JSON in-string by Key then by Value?

I have an application that can compare JSON response from multiple deployments written in Groovy (Based on JDK8). The purpose was like to compare JSON response that I'm getting from multiple servers. For now, the response that I'm getting is not in…
Md. Hasan Basri
  • 159
  • 1
  • 15
0
votes
1 answer

Cannot parse response body content in katalon studio

I’m facing a problem, where I can’t parse response body content. Here is what I use for parsing, that works for another responses but for current response it doesn’t work. String getContent = get_response.getResponseBodyContent() JsonSlurper slurper…
brithwulf
  • 538
  • 10
  • 35
0
votes
2 answers

Access values in JSON based on a condition using Groovy

I am trying to extract two sets of information from the httpResponse (in the form of JSON)- 1. Location 2. city where fruit = Apple and luckyNumber = 10. { "userInformation": { "Name": "John", "Location": "India" }, …
ComplexData
  • 1,091
  • 4
  • 19
  • 36
0
votes
3 answers

Groovy get object within json slurper object with string

I'm trying create a function in which I pass a json object from JsonSlurper and a string which contains json object located in the original. If it does, it returns true or false if the elements count condition is satisfied. For example: myJson: { …
usr4896260
  • 1,427
  • 3
  • 27
  • 50
0
votes
1 answer

Add new key and value pair under map using groovy

{ "map": { "key1": [3,12,13,11], "key2": [21,23], "key3": [31,32,33] }} I have this JSON. similar to key1 or key2 I want to add new key- pair to this json using groovy. I am using JsonSlurper(). def mJson = new…
knowdotnet
  • 839
  • 1
  • 15
  • 29
0
votes
1 answer

How can I stop JsonSlurper from converting objects/maps to arrays?

I have a JSON response item from a web service that looks like this: [ { "field1":"value", "field2":"value2", "field3":"value3", "field4":"value4" }, { "field1":"value", "field2":"value2", …
Fueled By Coffee
  • 2,467
  • 7
  • 29
  • 43
0
votes
1 answer

Get JsonSlurper attributes with groovy

I have a Json file like this : { "type" : "record", "name" : "test", "fields" : [ { "name" : "y", "type" : { "type" : "array", "items" : "double" }, "doc" : "Type inferred from…
amira khalifa
  • 107
  • 3
  • 11
0
votes
2 answers

How to assert array json in groovy

My JSON response looks like below { "pCategories": [ "pogc1", "pogc16", "pogc2", "testc1122", "testcat10012018", "testcat10012019", "testcat100120191", "testcat11012018", …
Hanumanth
  • 102
  • 1
  • 1
  • 8
0
votes
1 answer

How to reference parent names in JSON response (with Groovy)

I have the following JSON response in SoapUI { "formatted": { "line1": "14/8 QUAY STREET", "line2": "14/8 QUAY STREET" }, "structure": { "level": null }, "location": { "nzX": 1758749.75300025 …
AutomateFr33k
  • 562
  • 2
  • 8
  • 26
0
votes
1 answer

Get java.lang.IllegalArgumentException: argument type mismatch for some but not all attempts to change JSON attribute value

IDE: IntelliJ IdEA 2017.2.4 Language: Groovy 2.4.11 Test Framework: Spock 1.1-groovy-2.4 New to all of the above. No prior experience in Java either. First post here and I actually read the intro and guidelines and trying my best to follow. JSON…
SleepyD
  • 39
  • 1
  • 2
  • 9
0
votes
1 answer

How to prevent ordering of json string during parsing using groovy jsonslurper?

I have a josn string like below, def input = '''{"name":"abul","age":30,"street":"Uttara"}''' After parsing json string input like below, def output = new groovy.json.JsonSlurper().parseText(input) I got following value of output…
Jakir Hosen Khan
  • 1,498
  • 1
  • 14
  • 17
0
votes
1 answer

groovy JsonSlurper assertion for random number, random alphanumeric and date

I am pretty new to service testing and Groovy. The following is my response, { encodedDiscountId=1275479, encodedGuid=gOHSkGzQEee4-AJiXJP2jg, expirationDate=2017-08-17 17:00:00 } I need help for the following assertions: I need…
peter
  • 391
  • 1
  • 4
  • 17
0
votes
2 answers

Groovy: Implementing JsonSlurper is giving a JsonException --- Usually works

I am trying to build a json request in SoapUI and trying to post to a test step. For building the request, I have below code. When I execute it, it is throwing a JsonException (text provided below.) Any advise would be greatly appreciated. I have…
ssc
  • 35
  • 2
  • 9
0
votes
1 answer

Flatten JSON read with JsonSlurper

Trying to read and transform a JSON file where the input file has: { "id": “A9”, "roles": [ {"title": “A”, “type”: “alpha” }, {"title": “B”, “type”: “beta” }, ] }, { "id": “A10”, "roles": [ {"title": “D”, “type”: “delta” }, ] },…
Brad Schoening
  • 1,281
  • 6
  • 22
1 2 3
8 9