1

I'm trying to parse a JSON-File in my gradle task.

CODE:

def jsonFile = "../files/json/myJSON.json"
def list = new JsonSlurper().parseText(jsonFile)

JSON - FILE

{
   "prepare": {
       "installed": [],
       "uninstalled": []
   },
   "config": {
       "files": []
   }
}

But the code gives me the following exception:

Lexing failed on line: 1, column: 1, while reading '.', no possible valid JSON value or punctuation could be recognized.

And I don't understand why, I also validated my JSON-File on http://jsonlint.com/ and it says that it is a valid JSON!

Paul
  • 1,325
  • 2
  • 19
  • 41

1 Answers1

1

Above code is trying to parse the string ../files/json/myJSON.json as JSON. Instead use:

def jsonFile = new File("../files/json/myJSON.json")
def map = new JsonSlurper().parse(jsonFile)
Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259