{"id":21813530,"url":"https://github.com/loggerhead/json-map-ts","last_synced_at":"2025-07-26T11:02:49.664Z","repository":{"id":57284986,"uuid":"455573182","full_name":"loggerhead/json-map-ts","owner":"loggerhead","description":null,"archived":false,"fork":false,"pushed_at":"2022-02-10T10:26:33.000Z","size":203,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-26T06:09:05.015Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/loggerhead.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":"2022-02-04T14:16:14.000Z","updated_at":"2024-10-31T07:53:42.000Z","dependencies_parsed_at":"2022-08-24T18:14:14.632Z","dependency_job_id":null,"html_url":"https://github.com/loggerhead/json-map-ts","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/loggerhead%2Fjson-map-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loggerhead%2Fjson-map-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loggerhead%2Fjson-map-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loggerhead%2Fjson-map-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loggerhead","download_url":"https://codeload.github.com/loggerhead/json-map-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244768679,"owners_count":20507309,"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-11-27T14:29:48.417Z","updated_at":"2025-03-21T09:23:07.174Z","avatar_url":"https://github.com/loggerhead.png","language":"TypeScript","readme":"# json-map-ts\n\nA TypeScript port of [json-source-map](https://github.com/epoberezkin/json-source-map) used for [json4u.com](http://json4u.com). Difference from the origin:\n\n- Support only ES6 or later.\n- Enable bigint by default.\n- Line start from 1 instead of\n- Throw error with custom type.\n\nParse/stringify JSON and provide source-map for JSON-pointers to all nodes (supports BigInt, Maps, Sets and Typed arrays).\n\n[![Build Status](https://travis-ci.org/epoberezkin/json-source-map.svg?branch=master)](https://travis-ci.org/epoberezkin/json-source-map)\n[![npm version](https://badge.fury.io/js/json-source-map.svg)](https://www.npmjs.com/package/json-source-map)\n[![Coverage Status](https://coveralls.io/repos/github/epoberezkin/json-source-map/badge.svg?branch=master)](https://coveralls.io/github/epoberezkin/json-source-map?branch=master)\n\n\n## Install\n\n```bash\nnpm install json-source-map\n```\n\n\n## Possible use cases\n\n#### Source maps\n\nWhen a domain-specific language that compiles to JavaScript uses JSON as a format, this module can be used as a replacement for standard JSON to simplify generation of source maps.\n\n#### Editing forms/JSON\n\nWhen a form also allows to edit JSON representation of data on the same screen, this module can be used to sinchronise navigation in JSON and in the form.\n\n\n## Usage\n\n#### Stringify\n\n```javascript\nvar jsonMap = require('json-source-map');\nvar result = jsonMap.stringify({ foo: 'bar' }, null, 2);\nconsole.log('json:');\nconsole.log(result.json);\nconsole.log('\\npointers:');\nconsole.log(result.pointers);\n```\n\noutput:\n\n```text\njson:\n{\n  \"foo\": \"bar\"\n}\n\npointers:\n{ '':\n   { value: { line: 0, column: 0, pos: 0 },\n     valueEnd: { line: 2, column: 1, pos: 18 } },\n  '/foo':\n   { key: { line: 1, column: 2, pos: 4 },\n     keyEnd: { line: 1, column: 7, pos: 9 },\n     value: { line: 1, column: 9, pos: 11 },\n     valueEnd: { line: 1, column: 14, pos: 16 } } }\n```\n\n\n#### Parse\n\n```javascript\nvar result = jsonMap.parse('{ \"foo\": \"bar\" }');\nconsole.log('data:')\nconsole.log(result.data);\nconsole.log('\\npointers:');\nconsole.log(result.pointers);\n```\n\noutput:\n```text\ndata:\n{ foo: 'bar' }\n\npointers:\n{ '':\n   { value: { line: 0, column: 0, pos: 0 },\n     valueEnd: { line: 0, column: 16, pos: 16 } },\n  '/foo':\n   { key: { line: 0, column: 2, pos: 2 },\n     keyEnd: { line: 0, column: 7, pos: 7 },\n     value: { line: 0, column: 9, pos: 9 },\n     valueEnd: { line: 0, column: 14, pos: 14 } } }\n```\n\n\n## API\n\n#### .parse(String json, Any _, Object options) -\u0026gt; Object;\n\nParses JSON string. Returns object with properties:\n- _data_: parsed data.\n- _pointers_: an object where each key is a JSON pointer ([RFC 6901](https://tools.ietf.org/html/rfc6901)), each corresponding value is a mapping object.\n\nMapping object has properties:\n- _key_: location object (see below) of the beginning of the key in JSON string. This property is only present if parent data is an object (rather than array).\n- _keyEnd_: location of the end of the key in JSON string. This property is only present if parent data is an object.\n- _value_: location of the beginning of the value in JSON string.\n- _valueEnd_: location of the end of the value in JSON string.\n\nLocation object has properties (zero-based numbers):\n- _line_: line number in JSON file.\n- _column_: column number in JSON string (from the beginning of line).\n- _pos_: character position in JSON file (from the beginning of JSON string).\n\nOptions:\n- _bigint_: parse large integers as [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt).\n\nWhitespace:\n- the only character that increases line number in mappings is line feed ('\\n'), so if your JSON string has '\\r\\n' sequence, it will still be counted as one line,\n- both '\\r' and '\\n' are counted as a character when determining `pos` (it is possible to slice sections of JSON string using `pos` property), but `column` counter is reset when `r` or `n` is encountered,\n- tabs ('\\t') are counted as four spaces when determining `column` but as a single character for `pos`.\n\nComparison with the standard `JSON.parse`:\n- when it is not possible to parse JSON, a SyntaxError exception with exactly the same message is thrown,\n- `reviver` parameter of [JSON.parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter) is not supported, but its position is reserved.\n- supports parsing large integers as [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) (with the option `bigint: true`).\n\n\n#### .stringify(Any data, Any _, String|Number|Object space) -\u0026gt; Object;\n\nStringifies JavaScript data. Returns object with properties:\n- _json_: JSON string - stringified data.\n- _pointers_: an object where each key is a JSON-pointer, each corresponding value is a mapping object (same format as in parse method).\n\nComparison with the standard `JSON.stringify`:\n- `replacer` parameter of [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) is not supported, but its position is reserved.\n- `space` parameter is supported, but if it is a string, it may only contain characters space, tab ('\\t'), caret return ('\\r') and line feed ('\\n') - using any other caracter throws an exception. If this parameter is an object, it is options.\n\nOptions:\n- _space_: same as `space` parameter.\n- _es6_: stringify ES6 Maps, Sets and Typed arrays (as JSON arrays).\n\n\n## License\n\n[MIT](https://github.com/epoberezkin/json-source-map/blob/master/LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floggerhead%2Fjson-map-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floggerhead%2Fjson-map-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floggerhead%2Fjson-map-ts/lists"}