I am facing a problem. I have to parse JSON contained list of jira-core versions from Atlassian website.

While attempting to parse JSON from the website using a JsonSlurper, I get an error saying:

"The current character read is 'd' with an int value of 100 Unable to determine the current character, it is not a string, number, array, or object line number 1 index number 0"

Code:

def http = new HTTPBuilder('https://my.atlassian.com/download/feeds/')
def html = http.get( path : 'current/jira-core.json')
def slurper = new groovy.json.JsonSlurper(type: JsonParserType.LAX).parse(html)
print slurper

How do I need to get the correct JSON block?

2 Answers

1
tim_yates On Best Solutions

The problem is, that's not json... It's a jsonp callback, so the valid json is wrapped in a downloads( ... ) javascript call

You can use a regular expression to unwrap the text from the URL with:

import groovy.json.*

def jsonp = new URL('https://my.atlassian.com/download/feeds/current/jira-core.json').text
def extract = jsonp =~ /^downloads\((.+)\)$/
if (!extract.matches()) {
    throw new RuntimeException("Bad jsonp!")
}
def parsed = new JsonSlurper().parseText(extract.group(1))

parsed.each { println it.description }
0
Scott Dudley On

While this doesn't directly address the JSON vs JSONP issue, if you are just looking to consume Jira version data, there is also a third-party site called iapetus.fyi that provides Atlassian product version information, including the possibility of providing Firebase notifications to your app for version change events.