{"id":13670455,"url":"https://github.com/JohannesOehm/json-parse-ast","last_synced_at":"2025-04-27T13:32:17.693Z","repository":{"id":57140645,"uuid":"340898360","full_name":"JohannesOehm/json-parse-ast","owner":"JohannesOehm","description":"JSON AST parser written in JavaScript. For usage in conjunction with the monaco editor to enhance JSON autocomplete experience.","archived":false,"fork":false,"pushed_at":"2021-02-25T13:12:36.000Z","size":121,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T02:58:04.723Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JohannesOehm.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-21T12:39:37.000Z","updated_at":"2025-03-18T17:20:58.000Z","dependencies_parsed_at":"2022-09-01T22:41:44.820Z","dependency_job_id":null,"html_url":"https://github.com/JohannesOehm/json-parse-ast","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohannesOehm%2Fjson-parse-ast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohannesOehm%2Fjson-parse-ast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohannesOehm%2Fjson-parse-ast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohannesOehm%2Fjson-parse-ast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JohannesOehm","download_url":"https://codeload.github.com/JohannesOehm/json-parse-ast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251145628,"owners_count":21543074,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T09:00:42.705Z","updated_at":"2025-04-27T13:32:16.775Z","avatar_url":"https://github.com/JohannesOehm.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# json-parse-ast\nJSON Tokenizer \u0026 AST (Abstract Syntax Tree) parser\n\n## Background\nI wrote my custom parser since [monaco's](https://microsoft.github.io/monaco-editor/) built-in JSON\nlibrary does not expose any syntax tree which can be used to check position in file and enhance \nautocomplete experience.\n\n## Usage\nCurrently, only tokenizer is stable:\n```javascript\nvar tokens = tokenize('{\"json\": \"string\"}'); //returns list of tokens\n//tokens have the following attributes\n// type: \"inlinecomment\"|\"multilinecomment\"|\"whitespace\"|\"string\"|\"literal\"|\"number\"|\"punctuaction\" \n// position: IRange compatible with monaco's IRange-interface\n// raw: string \n// value: string Unescaped JSON string, parsed number, parsed literal (null, true, false)\n```\n## Tokenizer additional features\n```javascript\nvar [path, willBeValue] = getPathInObject(tokenize('{\"foo\": {\"bar\": \"'));\n//returns path == [\"foo\", \"bar\"] and willBeValue == true\n```\n\n## Parser\n```javascript\nvar ast = parseTokens(tokenize(testString));\n//AST elements have\n// type \n// position: IRange\n// raw: string\n// value?: string\n// parent?: AST \n// children?: AST[]\n\n//Find node at specified position\nvar node = findAtPosition(ast, {lineNumber: 4, column: 16})\n```\n\n## Usage with monaco\nThis libraries intended use is for enhancing experience with custom JSON formats. See example use-cases below:\n\n### Enhancing autocomplete/IntelliSense\n```javascript\nmonaco.languages.registerCompletionItemProvider('json', {\n    provideCompletionItems: function(model, position) {\n        let textUntilPosition = model.getValueInRange({startLineNumber: 1, startColumn: 1, endLineNumber: position.lineNumber, endColumn: position.column});\n        let [jsonPath, willBeValue] = getPathInObject(tokenize(textUntilPosition));\n        if (willBeValue \u0026\u0026 jsonPath[jsonPath.length-1] === \"dependencies\") {\n             return { suggestions: listDependencies() };\n        } else {\n             return { suggestions: [] };\n        }\n    }\n});\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJohannesOehm%2Fjson-parse-ast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJohannesOehm%2Fjson-parse-ast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJohannesOehm%2Fjson-parse-ast/lists"}