Czytanie obiektu JSON z pliku txt w Groovy

Próbuję zebrać JSON z pliku txt. Ale mój poniższy kod wydaje mi się „nullPointerException”.

File f = new File(tempDir+File.separator+'jsonObject.txt')
if (f){
    log.error " file exists $f"
    FileReader f2 = new FileReader(f);
    log.error " file data- $f2"
    if (f2 == null) {
        //do something
    } else {
        JsonSlurper jsonParser = new JsonSlurper();
        game = jsonParser.parse(new FileReader(f));
    }
} 

ROZWIĄZANIE ROZWIĄZANE
Czytanie pliku json txt:

File f = new File(tempDir+File.separator+'jsonObject.txt')
def slurper = new JsonSlurper()
def jsonText = f.getText()
json = slurper.parseText( jsonText )

Pisanie json do pliku:

File g = new File(tempDir+File.separator+'jsonObject.txt')
            g.createNewFile()
            def json = new JsonBuilder()
            json {
                "result" result
                }       
            g.setText(json.toString())

questionAnswers(3)

yourAnswerToTheQuestion