Forum Discussion

Meerkat's avatar
Meerkat
New Contributor
13 years ago

Null error parsing very long JSON response from REST service

I'm new to SoapUI and Groovy so I am unsure how to go about parsing a JSON response that is quite long, e.g. the one I am currently looking at is 400k+ characters long.
I have been using the following code to get the request response and then parse it which has worked fine for the other responses which have all been a lot shorter.

import groovy.json.JsonSlurper
def response = messageExchange.response.responseContent
def slurper = new JsonSlurper()
def json = slurper.parseText response


When I use the above code with the long JSON responses then I get a null returned.

I have also tried using a stream reader version of the code but it also returns a null

import java.net.URL
import java.io.InputStream
import java.io.BufferedReader
import java.io.InputStreamReader
import groovy.json.JsonSlurper
import java.util.Map

URL url = new URL("http://api.rest.url/endpoint")
InputStream urlStream = url.openStream()
BufferedReader reader = new BufferedReader(new InputStreamReader(urlStream))
JsonSlurper parser = new JsonSlurper()
Object result = parser.parse(reader)
jsonResponse = (Map) result


I believe it is something to do with the length of the response as I am able to request a subset of the full response which works using either method so it is unlikely to be the content at fault.

Is there some way to parse responses of that length or do I have an error in my code that is artificially limiting what I can parse?
No RepliesBe the first to reply