{"record":{"id":"de4719169a4540da","repo":"eclipse-vertx/vert.x","slug":"invalid-json-object-json","errorCode":null,"errorMessage":"Invalid JSON object: ${json}","messagePattern":"Invalid JSON object: (.+?)","errorType":"exception","errorClass":"DecodeException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/json/JsonObject.java","lineNumber":54,"sourceCode":" *\n * @author <a href=\"http://tfox.org\">Tim Fox</a>\n */\npublic class JsonObject implements Iterable<Map.Entry<String, Object>>, ClusterSerializable, Shareable {\n\n  private Map<String, Object> map;\n\n  /**\n   * Create an instance from a string of JSON\n   *\n   * @param json the string of JSON\n   */\n  public JsonObject(String json) {\n    if (json == null) {\n      throw new NullPointerException();\n    }\n    fromJson(json);\n    if (map == null) {\n      throw new DecodeException(\"Invalid JSON object: \" + json);\n    }\n  }\n\n  /**\n   * Create a new, empty instance\n   */\n  public JsonObject() {\n    map = new LinkedHashMap<>();\n  }\n\n  /**\n   * Create an instance from a Map. The Map is not copied.\n   *\n   * @param map the map to create the instance from.\n   */\n  public JsonObject(Map<String, Object> map) {\n    if (map == null) {\n      throw new NullPointerException();","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/json/JsonObject.java#L36-L72","documentation":"The JsonObject(String) constructor parses the string with Jackson; when the parsed value is not a JSON object (array, scalar, or malformed), the internal map stays null and DecodeException(\"Invalid JSON object: <json>\") is thrown.","triggerScenarios":"new JsonObject(string) where the string is a JSON array (\"[1,2]\"), a scalar (\"\\\"text\\\"\", \"42\"), an empty string, or invalid JSON.","commonSituations":"Passing a JSON array where an object is expected; empty config file or env string; config service returning an array; trailing garbage after the object.","solutions":["If the string starts with '[', parse with new JsonArray(json) instead.","Trim the string and remove BOM/trailing whitespace before parsing.","Validate the JSON shape with Jackson readTree before constructing.","Catch DecodeException when parsing untrusted input and surface a clear config error."],"exampleFix":"// before\nJsonObject cfg = new JsonObject(configString); // may be [..]\n// after\nString s = configString.trim();\nJsonObject cfg = s.startsWith(\"{\") ? new JsonObject(s) : null;","handlingStrategy":"validation","validationCode":"boolean isJsonObject(String s) { return s != null && s.trim().startsWith(\"{\"); }","typeGuard":"JsonObject safeObject(String json) { return json != null && json.trim().startsWith(\"{\") ? new JsonObject(json) : null; }","tryCatchPattern":"try { obj = new JsonObject(json); } catch (DecodeException e) { /* handle array/scalar/invalid payload */ }","preventionTips":["Sniff the first non-whitespace character ('{' vs '[') before parsing","Trim whitespace/BOM from config strings and file contents","Fail with a clear message when a config source returns an unexpected JSON type"],"tags":["json","decode","jsonobject"],"backgroundTag":"json-decode-failed","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}