{"record":{"id":"9a3ce7dc97a453ee","repo":"json-path/JsonPath","slug":"use-bracket-notion-my-prop-if-your-property-co","errorCode":null,"errorMessage":"Use bracket notion ['my prop'] if your property contains blank characters. position: ","messagePattern":"Use bracket notion \\['my prop'\\] if your property contains blank characters\\. position: ","errorType":"exception","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java","lineNumber":194,"sourceCode":"    }\n\n    //\n    // fooBar or fooBar()\n    //\n    private boolean readPropertyOrFunctionToken(PathTokenAppender appender) {\n        if (path.currentCharIs(OPEN_SQUARE_BRACKET) || path.currentCharIs(WILDCARD) || path.currentCharIs(PERIOD) || path.currentCharIs(SPACE)) {\n            return false;\n        }\n        int startPosition = path.position();\n        int readPosition = startPosition;\n        int endPosition = 0;\n\n        boolean isFunction = false;\n\n        while (path.inBounds(readPosition)) {\n            char c = path.charAt(readPosition);\n            if (c == SPACE) {\n                throw new InvalidPathException(\"Use bracket notion ['my prop'] if your property contains blank characters. position: \" + path.position());\n            }\n            else if (c == PERIOD || c == OPEN_SQUARE_BRACKET) {\n                endPosition = readPosition;\n                break;\n            }\n            else if (c == OPEN_PARENTHESIS) {\n                isFunction = true;\n                endPosition = readPosition;\n                break;\n            }\n            readPosition++;\n        }\n        if (endPosition == 0) {\n            endPosition = path.length();\n        }\n\n\n        List<Parameter> functionParameters = null;","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java#L176-L212","documentation":"Property names in dot notation may not contain spaces. When readPropertyOrFunctionToken encounters a SPACE while scanning a property name, compilation aborts with InvalidPathException telling the user to switch to bracket notation ['my prop'].","triggerScenarios":"Paths like `$.first name`, `$['a'].my prop`, or reading JSON with keys containing spaces using dot notation, e.g. `$.address line 1`.","commonSituations":"JSON produced from CSV headers or form fields with spaces in key names; XML-derived keys like `<first name>` mapped to JSON; users unaware dot notation can't express such keys.","solutions":["Use bracket notation with quotes: `$.['first name']` or `$['first name']`.","Prefer bracket notation whenever keys are dynamic or may contain spaces/special characters.","Normalize the document keys (strip spaces) upstream if you control the data."],"exampleFix":"// before\nJsonPath.read(json, \"$.first name\");\n// after\nJsonPath.read(json, \"$['first name']\");","handlingStrategy":"validation","validationCode":"String toBracketNotation(String path) {\n    return path.replaceAll(\"\\\\.([^.\\\\[\\]]*\\\\s[^.\\\\[\\]]*)\", \"['$1']\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return JsonPath.read(json, path);\n} catch (InvalidPathException e) {\n    throw new IllegalArgumentException(\"Property with spaces? Use ['prop name']: \" + path, e);\n}","preventionTips":["Default to bracket notation ['key'] for any key that may contain spaces or special characters.","When mapping external data (CSV headers, XML tags), inspect key names before writing dot-notation paths.","Escape/normalize keys upstream when possible."],"tags":["json-path","invalid-path","syntax","property"],"backgroundTag":"invalid-argument-format","analyzedSha":"62a4c9f0f65ba3f625aa0867d64c528ba72d09ec","analyzedAt":"2026-09-11T11:36:00.448Z","contentChangedAt":"2026-09-11T11:36:00.448Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}