Vam Vam - 9 months ago 52
JSON Question

json file parsing in groovy

the below code is working fine in windows (groovy script shell of jenkins) and when i execute it on groovy script shell of jenkins in linux its throwing the error

groovy.lang.MissingMethodException: No signature of method: sun.nio.fs.UnixPath.withReader() is applicable for argument types: (Script1$_run_closure1) values: [Script1$_run_closure1@71c12adb]
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
at org.jenkinsci.plugins.scriptler.util.ScriptHelper.runScript(
at org.jenkinsci.plugins.scriptler.util.ScriptHelper.runScript(
at org.jenkinsci.plugins.scriptler.ScriptlerManagement.doTriggerScript(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(

i pass the value for Select_Folders

import groovy.json.JsonSlurper
import java.nio.file.Paths

JsonSlurper slurper = new JsonSlurper()
def folder_struct

Paths.get('C:\\Json_Results\\results.json').withReader { reader ->
folder_struct = slurper.parse(reader)

return folder_struct [Select_Folders]

Could any one please help me where the problem is? ofcorse i have changed the path 'C:\Json_Results\results.json' when running on linux to '/home/project/results.json'

Answer Source

So Path extensions were only added to Groovy in v2.3.0

I suspect you have an old version of Groovy on your Jenkins nodes.

You should just be able to use a File instead:

def folder_struct = new File('C:\\Json_Results\\results.json').withReader { reader ->