Skip to content
Latchkey

Jenkins readJSON/writeJSON Failure - Fix Pipeline Utility Steps

readJSON/writeJSON (from Pipeline Utility Steps) failed. Usually the input is not valid JSON, the file/text argument is missing or empty, or the Pipeline Utility Steps plugin is not installed so the step does not exist.

What this error means

A pipeline fails with a net.sf.json.JSONException from readJSON, a "No such file" reading a JSON file, or No such DSL method 'readJSON' when the plugin is absent. The step could not parse or locate the JSON.

Jenkins console
net.sf.json.JSONException: A JSONObject text must begin with '{' at character 0
	at ... readJSON
# or, plugin missing:
No such DSL method 'readJSON' found among steps [...]

Common causes

Malformed or empty JSON input

The text or file passed to readJSON is not valid JSON - empty, a trailing comma, single quotes, or command output that was not actually JSON.

Missing file or wrong argument

Passing file: to a path that does not exist (or mixing file:/text:) makes the read fail. writeJSON needs a serializable map, not a non-serializable object.

Pipeline Utility Steps plugin not installed

Without the Pipeline Utility Steps plugin, readJSON/writeJSON are unknown DSL methods.

How to fix it

Read/write valid JSON with the right argument

Use file: for a path or text: for a string, and ensure the content is valid JSON.

Jenkinsfile
def cfg = readJSON file: 'config.json'        // path must exist
def obj = readJSON text: sh(returnStdout: true, script: 'cat data.json')
writeJSON file: 'out.json', json: [build: env.BUILD_NUMBER]

Install the plugin and validate input

  1. Install "Pipeline Utility Steps" if the step is unknown.
  2. Print the JSON before parsing (sh 'cat config.json') to confirm it is well-formed.
  3. Pass only serializable maps/lists to writeJSON.

How to prevent it

  • Validate JSON inputs (jq/lint) before feeding them to readJSON.
  • Keep Pipeline Utility Steps installed where pipelines use readJSON/writeJSON.
  • Pass serializable maps to writeJSON, not parsed non-serializable objects.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →