{"id":18447767,"url":"https://github.com/stoplightio/json","last_synced_at":"2025-04-04T12:06:43.280Z","repository":{"id":34085068,"uuid":"157507373","full_name":"stoplightio/json","owner":"stoplightio","description":"Useful functions when working with JSON.","archived":false,"fork":false,"pushed_at":"2024-12-09T09:31:34.000Z","size":1557,"stargazers_count":29,"open_issues_count":22,"forks_count":6,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-28T10:54:50.542Z","etag":null,"topics":["json","json-path","json-pointer"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stoplightio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-14T07:18:04.000Z","updated_at":"2024-12-22T23:42:33.000Z","dependencies_parsed_at":"2024-06-18T08:41:34.797Z","dependency_job_id":"e2230db3-202a-4631-a96c-8e90eff354db","html_url":"https://github.com/stoplightio/json","commit_stats":{"total_commits":130,"total_committers":23,"mean_commits":"5.6521739130434785","dds":0.7076923076923076,"last_synced_commit":"8cced792ae465a7e2d2628367079e7917c4e93d0"},"previous_names":[],"tags_count":89,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stoplightio%2Fjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stoplightio%2Fjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stoplightio%2Fjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stoplightio%2Fjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stoplightio","download_url":"https://codeload.github.com/stoplightio/json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247174407,"owners_count":20896076,"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":["json","json-path","json-pointer"],"created_at":"2024-11-06T07:14:23.316Z","updated_at":"2025-04-04T12:06:43.258Z","avatar_url":"https://github.com/stoplightio.png","language":"TypeScript","readme":"# @stoplight/json\n\n[![Maintainability](https://api.codeclimate.com/v1/badges/85d2215f8b1e8a15214f/maintainability)](https://codeclimate.com/github/stoplightio/json/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/85d2215f8b1e8a15214f/test_coverage)](https://codeclimate.com/github/stoplightio/json/test_coverage)\n\nUseful functions when working with JSON.\n\n- View the changelog: [Releases](https://github.com/stoplightio/json/releases)\n\n### Installation\n\nSupported in modern browsers and node.\n\n```bash\n# latest stable version\nyarn add @stoplight/json\n```\n\n### Usage\n\n- **[parseWithPointers](https://stoplightio.github.io/json/globals.html#parsewithpointers)**: Like `JSON.parse(val)` but also returns parsing errors as well as full ast with line information.\n- **[pathToPointer](https://stoplightio.github.io/json/globals.html#pathtopointer)**: Turns an array of path segments into a json pointer IE `['paths', '/user', 'get']` -\u003e `#/paths/~1user/get`.\n- **[pointerToPath](https://stoplightio.github.io/json/globals.html#pointertopath)**: Turns a json pointer into an array of path segments IE `#/paths/~1user/get` -\u003e `['paths', '/user', 'get']`.\n- **[safeParse](https://stoplightio.github.io/json/globals.html#safeparse)**: Like `JSON.parse(val)` but does not throw on invalid JSON.\n- **[safeStringify](https://stoplightio.github.io/json/globals.html#safestringify)**: Like `JSON.stringify(val)` but handles circular references.\n- **[startsWith](https://stoplightio.github.io/json/globals.html#startswith)**: Like native JS `x.startsWith(y)` but works with strings AND arrays.\n- **[trimStart](https://stoplightio.github.io/json/globals.html#trimstart)**: Like `lodash.startsWith(x, y)` but works with strings AND arrays.\n- **[getJsonPathForPosition](https://stoplightio.github.io/json/globals.html#getjsonpathforposition)**: Computes JSON path for given position.\n- **[getLocationForJsonPath](https://stoplightio.github.io/json/globals.html#getlocationforjsonpath)**: Retrieves location of node matching given JSON path.\n\n#### Example `parseWithPointers`\n\n```ts\nimport { parseWithPointers } from \"@stoplight/json\";\n\nconst result = parseWithPointers('{\"foo\": \"bar\"}');\n\nconsole.log(result.data); // =\u003e the {foo: \"bar\"} JS object\nconsole.log(result.pointers); // =\u003e the source map with a single \"#/foo\" pointer that has position info for the foo property\n```\n\n```ts\n// basic example of getJsonPathForPosition and getLocationForJsonPath\nimport { getJsonPathForPosition, getLocationForJsonPath, parseWithPointers } from \"@stoplight/json\";\n\nconst result = parseWithPointers(`{\n  \"hello\": \"world\",\n  \"address\": {\n    \"street\": 123\n  }\n}`);\n\nconst path = getJsonPathForPosition(result, { line: 3, character: 15 }); // line and character are 0-based\nconsole.log(path); // -\u003e [\"address\", \"street\"];\n\nconst position = getLocationForJsonPath(result, [\"address\"]);\nconsole.log(position.range.start); // { line: 2, character: 13 } line and character are 0-based\nconsole.log(position.range.end); // { line: 4, character: 3 } line and character are 0-based\n```\n\n### Contributing\n\n1. Clone repo.\n2. Create / checkout `feature/{name}`, `chore/{name}`, or `fix/{name}` branch.\n3. Install deps: `yarn`.\n4. Make your changes.\n5. Run tests: `yarn test.prod`.\n6. Stage relevant files to git.\n7. Commit: `yarn commit`. _NOTE: Commits that don't follow the [conventional](https://github.com/marionebl/commitlint/tree/master/%40commitlint/config-conventional) format will be rejected. `yarn commit` creates this format for you, or you can put it together manually and then do a regular `git commit`._\n8. Push: `git push`.\n9. Open PR targeting the `next` branch.\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstoplightio%2Fjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstoplightio%2Fjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstoplightio%2Fjson/lists"}