https://github.com/mischnic/json-sourcemap
Generate positions for values in JSON and JSON5 strings
https://github.com/mischnic/json-sourcemap
json json5
Last synced: 2 months ago
JSON representation
Generate positions for values in JSON and JSON5 strings
- Host: GitHub
- URL: https://github.com/mischnic/json-sourcemap
- Owner: mischnic
- License: mit
- Created: 2022-04-10T15:57:33.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-09-20T14:11:17.000Z (over 2 years ago)
- Last Synced: 2025-08-17T11:16:51.385Z (5 months ago)
- Topics: json, json5
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@mischnic/json-sourcemap
- Size: 913 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @mischnic/json-sourcemap
Generate positions for values in JSON and JSON5 strings.
Inspired by and mostly API-compatible with https://github.com/epoberezkin/json-source-map.
## Usage
```ts
type Position = {
line: number;
column: number;
pos: number;
};
type Mapping =
| {
value: Position;
valueEnd: Position;
}
| {
value: Position;
valueEnd: Position;
key?: Position;
keyEnd?: Position;
};
export function parse(
json: string,
reviver?: (key: any, value: any) => any,
options?: {
tabWidth?: number;
dialect?: "JSON5" | "JSON";
}
): {
data: any;
pointers: Record;
};
```
The default `tabWidth` is 4.
The `valueEnd` and `keyEnd` positions are exclusive. `line`, `column` and `pos` are 0-based.