{"record":{"id":"fdece3d1e4ed87c2","repo":"apache/beam","slug":"failed-to-read-pipelineoptions-from-json","errorCode":null,"errorMessage":"Failed to read PipelineOptions from JSON","messagePattern":"Failed to read PipelineOptions from JSON","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/PipelineOptionsTranslation.java","lineNumber":126,"sourceCode":"    }\n  }\n\n  /** Converts the provided Json{@link String} into {@link PipelineOptions}. */\n  public static PipelineOptions fromJson(String optionsJson) {\n    try {\n      Map<String, Object> probingOptionsMap =\n          MAPPER.readValue(optionsJson, new TypeReference<Map<String, Object>>() {});\n      if (probingOptionsMap.containsKey(\"options\")) {\n        // Legacy options.\n        return MAPPER.readValue(optionsJson, PipelineOptions.class);\n      } else {\n        // Fn Options with namespace and version.\n        Struct.Builder builder = Struct.newBuilder();\n        JsonFormat.parser().merge(optionsJson, builder);\n        return fromProto(builder.build());\n      }\n    } catch (IOException e) {\n      throw new RuntimeException(\"Failed to read PipelineOptions from JSON\", e);\n    }\n  }\n\n  /** Converts the provided {@link PipelineOptions} into Json{@link String}. */\n  public static String toJson(PipelineOptions options) {\n    try {\n      return JsonFormat.printer().print(toProto(options));\n    } catch (InvalidProtocolBufferException e) {\n      throw new RuntimeException(\"Failed to convert PipelineOptions to JSON\", e);\n    }\n  }\n}\n","sourceCodeStart":108,"sourceCodeEnd":139,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/PipelineOptionsTranslation.java#L108-L139","documentation":"fromJson parses an options JSON string: modern format is a JSON object with 'options' key (URN-keyed) or a plain Protobuf Struct JSON. After determining the format and delegating to fromProto, any IOException from Jackson or JsonFormat parsing is wrapped in a RuntimeException with this message.","triggerScenarios":"Calling PipelineOptionsTranslation.fromJson with malformed JSON, or JSON whose shape matches neither the 'options' keyed format nor a valid Struct, causing JsonFormat.parser().merge or the Jackson read to throw IOException.","commonSituations":"Passing hand-written or truncated options JSON to job submission; a corrupted --pipelineOptions CLI value; copy-pasted JSON with BOM or syntax errors.","solutions":["Validate the options JSON with a JSON parser/linter before submitting","Ensure the JSON matches the expected shape: {\"options\": {\"beam:option:...\": value}} or a valid Struct object","Strip any non-JSON bytes (BOM, comments) and re-run fromJson"],"exampleFix":"// before\nString json = \"{options: {beam:option:appName}}}\"; // malformed\n// after\nString json = \"{\\\"options\\\": {\\\"beam:option:app_name:v1\\\": \\\"myapp\\\"}}\";","handlingStrategy":"validation","validationCode":"new com.fasterxml.jackson.databind.ObjectMapper().readTree(optionsJson); // throws JsonProcessingException if malformed","typeGuard":"boolean isJsonObject(String s) { try { return new ObjectMapper().readTree(s).isObject(); } catch (Exception e) { return false; } }","tryCatchPattern":"try { PipelineOptions o = PipelineOptionsTranslation.fromJson(json); } catch (RuntimeException e) { log.error(\"bad options JSON: {}\", json, e.getCause()); throw new IllegalArgumentException(\"Invalid pipeline options JSON\", e); }","preventionTips":["Lint options JSON before job submission","Match the documented shape {options:{urn:value}}","Strip BOM/whitespace from CLI-provided JSON"],"tags":["java","apache-beam","pipeline-options","json"],"backgroundTag":"json-parse-error","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}