0

I have a Grails service that sends a request to the JIRA REST API and returns JSON - When I try to use JsonSlurper to parse the JSON, I get the following error:

ERROR errors.GrailsExceptionResolver  - JsonException occurred when processing request: [GET] /osmDash/jira/storyComplete
Lexing failed on line: 1, column: 1, while reading 'j', no possible valid JSON value or punctuation could be recognized.

Here is the code in the controller:

def jsonFile = jiraService.fetchJQL('issuetype=Story AND status in (Resolved,Closed,Done) AND resolved>=-30d') as JSON

def jiraSlurper = new JsonSlurper()

def jiraResult = jiraSlurper.parseText('jsonFile').total

And this is what the JSON looks like when I render it in the page: {"total":1356,"issues":[],"startAt":0,"maxResults":0}

I was looking at groovy.json.JsonSlurper parse JSON, which seems simliar, but I couldn't get this method to work. I'm looking specifically to assign the "total" value to a variable.

This is the service that is returning the JSON:

def fetchJQL(String jql, Integer maxResults = 0, def fields = null) {
    jira.request(POST, JSON) { req ->
        uri.path = '/rest/api/2/search'
        headers.'Authorization' = authHash
        body = [jql: jql, maxResults: maxResults, fields: fields]

        response.success = { resp, json ->
            return json
        }

        response.failure = { resp ->
            println resp.statusLine.statusCode
            println resp.statusLine
        }
    }
Community
  • 1
  • 1
Tara
  • 21
  • 2
  • jiraSlurper.parseText('jsonFile') is parsing the string 'jsonFile' not the variable jsonFile – BZ. Aug 15 '14 at 17:10
  • Thanks, that makes sense... I still have When I use jiraSlurper.parseText(jsonFile) instead, I get a MissingMethodException error: ERROR errors.GrailsExceptionResolver - MissingMethodException occurred when processing request: [GET] /osmDash/jira/storyComplete No signature of method: groovy.json.JsonSlurper.parseText() is applicable for argument types: (grails.converters.JSON) values: [{"total":1350,"issues":[],"startAt":0,"maxResults":0}] – Tara Aug 15 '14 at 17:47
  • 1
    what is your service returning there? you cast to JSON and then pass it again into the slurper. if the service returns a (json-)string, then just remove the cast and it should work. – cfrick Aug 15 '14 at 18:58
  • @cfrick I added the code from the service above, I thought it was returning JSON, but it is very possible that I am wrong (someone else wrote it). If I don't cast to JSON and pass it to the slurper that way, I also get a MissingMethodException. – Tara Aug 15 '14 at 22:06

0 Answers0