{"record":{"id":"c1e2786389c8b765","repo":"grpc/grpc-java","slug":"failed-to-parse-json","errorCode":null,"errorMessage":"Failed to parse JSON","messagePattern":"Failed to parse JSON","errorType":"exception","errorClass":"XdsInitializationException","httpStatus":null,"severity":"critical","filePath":"xds/src/main/java/io/grpc/xds/client/BootstrapperImpl.java","lineNumber":103,"sourceCode":"\n  /**\n   * Reads and parses bootstrap config. The config is expected to be in JSON format.\n   */\n  @SuppressWarnings(\"unchecked\")\n  @Override\n  public BootstrapInfo bootstrap() throws XdsInitializationException {\n    String jsonContent;\n    try {\n      jsonContent = getJsonContent();\n    } catch (IOException e) {\n      throw new XdsInitializationException(\"Fail to read bootstrap file\", e);\n    }\n\n    Map<String, ?> rawBootstrap;\n    try {\n      rawBootstrap = (Map<String, ?>) JsonParser.parse(jsonContent);\n    } catch (IOException e) {\n      throw new XdsInitializationException(\"Failed to parse JSON\", e);\n    }\n\n    logger.log(XdsLogLevel.DEBUG, \"Bootstrap configuration:\\n{0}\", rawBootstrap);\n    return bootstrap(rawBootstrap);\n  }\n\n  @Override\n  public BootstrapInfo bootstrap(Map<String, ?> rawData) throws XdsInitializationException {\n    return bootstrapBuilder(rawData).build();\n  }\n\n  protected BootstrapInfo.Builder bootstrapBuilder(Map<String, ?> rawData)\n      throws XdsInitializationException {\n    BootstrapInfo.Builder builder = BootstrapInfo.builder();\n\n    List<?> rawServerConfigs = JsonUtil.getList(rawData, \"xds_servers\");\n    if (rawServerConfigs == null) {\n      throw new XdsInitializationException(\"Invalid bootstrap: 'xds_servers' does not exist.\");","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/xds/src/main/java/io/grpc/xds/client/BootstrapperImpl.java#L85-L121","documentation":"After reading the bootstrap file successfully, BootstrapperImpl.bootstrap() parses its contents with JsonParser.parse. If parsing throws IOException (malformed JSON), it is wrapped in XdsInitializationException(\"Failed to parse JSON\"). The bootstrap file must be valid JSON per the xDS bootstrap spec.","triggerScenarios":"The file referenced by GRPC_XDS_BOOTSTRAP (or the default bootstrap path) contains invalid JSON: truncation, YAML instead of JSON, comments, trailing commas, template placeholders left unsubstituted, or non-UTF8/binary content.","commonSituations":"Hand-edited bootstrap files with syntax errors; config-management tools rendering partial templates (e.g. unexpanded {{ }}); files copied with encoding corruption; YAML bootstrap examples pasted as .json.","solutions":["Validate the bootstrap file with a JSON parser (e.g. `jq . $GRPC_XDS_BOOTSTRAP`) and fix syntax errors.","Check that config templating actually rendered all placeholders before the process starts.","Regenerate the bootstrap file from your control plane / service mesh tooling rather than hand-editing.","Confirm the file is plain UTF-8 text, not YAML or binary."],"exampleFix":"// before: bootstrap file contains YAML or unrendered {{ .Values }}\n// after: valid JSON bootstrap file\n{\n  \"xds_servers\": [{ \"server_uri\": \"dns:///xds.example.com:443\",\n                     \"channel_creds\": [{\"type\": \"google_default\"}] }]\n}","handlingStrategy":"validation","validationCode":"String content = new String(java.nio.file.Files.readAllBytes(\n    java.nio.file.Paths.get(System.getenv(\"GRPC_XDS_BOOTSTRAP\"))),\n    java.nio.charset.StandardCharsets.UTF_8);\ntry (var parser = new com.google.gson.JsonParser()) {\n  parser.parseString(content); // throws if invalid JSON\n}","typeGuard":null,"tryCatchPattern":"try {\n  BootstrapInfo info = bootstrapper.bootstrap();\n} catch (XdsInitializationException e) {\n  if (e.getMessage().contains(\"Failed to parse JSON\")) {\n    // validate/repair bootstrap JSON before retrying\n  }\n}","preventionTips":["Run `jq . bootstrap.json` in CI or startup scripts to validate JSON.","Ensure config templating completes before process start (no leftover placeholders).","Keep bootstrap files in plain UTF-8 JSON, never YAML."],"tags":["grpc","xds","bootstrap","json","parse-error"],"backgroundTag":"json-parse-error","analyzedSha":"64daddc1f3d1975670f769f3e97bde8b2ba32d25","analyzedAt":"2026-09-08T06:14:57.704Z","contentChangedAt":"2026-09-08T06:14:57.704Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}