{"record":{"id":"9f243c37eaea35ee","repo":"kestra-io/kestra","slug":"invalid-json-e-getmessage","errorCode":null,"errorMessage":"Invalid json: {e.getMessage()}","messagePattern":"Invalid json: (.+?)","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/FromJsonFunction.java","lineNumber":48,"sourceCode":"        if (!args.containsKey(\"json\")) {\n            throw new PebbleException(null, \"The 'fromJson' function expects an argument 'json'.\", lineNumber, self.getName());\n        }\n\n        if (args.get(\"json\") == null) {\n            return null;\n        }\n\n        if (!(args.get(\"json\") instanceof String)) {\n            throw new PebbleException(null, \"The 'fromJson' function expects an argument 'json' with type string.\", lineNumber, self.getName());\n        }\n\n        String json = (String) args.get(\"json\");\n        ;\n\n        try {\n            return MAPPER.readValue(json, JacksonMapper.OBJECT_TYPE_REFERENCE);\n        } catch (JsonProcessingException e) {\n            throw new PebbleException(null, \"Invalid json: \" + e.getMessage(), lineNumber, self.getName());\n        }\n    }\n}\n","sourceCodeStart":30,"sourceCodeEnd":52,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/FromJsonFunction.java#L30-L52","documentation":"Thrown by 'fromJson' when Jackson's MAPPER.readValue raises a JsonProcessingException. The input was a string but not valid JSON, so parsing aborted; the message appends the Jackson parser's explanation (e.g. unexpected token, EOF).","triggerScenarios":"Passing fromJson() a malformed JSON string (trailing comma, unquoted keys, single quotes, truncated), a JSON5/YAML/INI string, or HTML/plain text mistaken for JSON.","commonSituations":"Reading a non-JSON file; an upstream API returning an error page instead of JSON; copy-pasting partial JSON; trailing commas or comments (not valid JSON).","solutions":["Validate the string is well-formed JSON (use jq or a linter) before passing it.","If the source is YAML or another format, convert it to JSON first or use the appropriate parser.","Handle API error responses (e.g. check status/content-type) before parsing the body as JSON.","For user-supplied JSON inputs, enable a JSON validation rule at the input boundary."],"exampleFix":"# before - YAML-ish content passed to fromJson()\nobj: \"{{ fromJson(readFile('config.yaml')) }}\"\n# after - ensure valid JSON content\nobj: \"{{ fromJson(readFile('config.json')) }}\"","handlingStrategy":"validation","validationCode":"# Light pre-check before fromJson(): must look like a JSON object or array.\n# {{ (jsonContent trim starts with '{' or jsonContent trim starts with '[') ? fromJson(jsonContent) : null }}","typeGuard":null,"tryCatchPattern":"# Pebble has no try/catch. In a wrapper task, catch JsonProcessingException and return a fallback or log the raw input.","preventionTips":["Validate the string is well-formed JSON (jq/linter) before parsing.","Check API status/content-type before parsing a response body.","Convert non-JSON formats upstream; do not feed YAML/INI to fromJson().","Add JSON validation at input boundaries for user-supplied payloads."],"tags":["pebble","fromjson","serialization","json","parse-error","validation"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}