
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
@mischnic/json-sourcemap
Advanced tools
@mischnic/json-sourcemap is an npm package that provides functionality to generate and work with source maps for JSON files. This can be particularly useful for debugging and understanding changes in JSON data structures by mapping positions in the JSON text to the corresponding data structures.
Generating Source Maps
This feature allows you to generate a JSON string along with a source map that maps positions in the JSON text to the corresponding data structures.
const { stringify } = require('@mischnic/json-sourcemap');
const obj = { foo: 'bar', baz: [1, 2, 3] };
const { json, pointers } = stringify(obj);
console.log(json); // JSON string
console.log(pointers); // Source map
Parsing JSON with Source Maps
This feature allows you to parse a JSON string and generate a source map that maps positions in the JSON text to the corresponding data structures.
const { parse } = require('@mischnic/json-sourcemap');
const json = '{"foo":"bar","baz":[1,2,3]}';
const { data, pointers } = parse(json);
console.log(data); // Parsed JSON object
console.log(pointers); // Source map
Querying Source Maps
This feature allows you to query the source map to find the position of specific elements in the JSON text.
const { parse } = require('@mischnic/json-sourcemap');
const json = '{"foo":"bar","baz":[1,2,3]}';
const { data, pointers } = parse(json);
const pointer = pointers['/baz/1'];
console.log(pointer); // { value: 2, valueEnd: 16, key: '1', keyEnd: 15, parent: '/baz' }
json-source-map is a package that provides similar functionality for generating and working with source maps for JSON files. It allows you to parse JSON strings and generate source maps, as well as query the source maps to find positions of elements in the JSON text. Compared to @mischnic/json-sourcemap, it offers a similar set of features but may have different performance characteristics or API design.
Generate positions for values in JSON and JSON5 strings.
Inspired by and mostly API-compatible with https://github.com/epoberezkin/json-source-map.
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<string, Mapping>;
};
The default tabWidth
is 4.
The valueEnd
and keyEnd
positions are exclusive. line
, column
and pos
are 0-based.
FAQs
Generate positions for values in JSON and JSON5 strings
The npm package @mischnic/json-sourcemap receives a total of 432,849 weekly downloads. As such, @mischnic/json-sourcemap popularity was classified as popular.
We found that @mischnic/json-sourcemap demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.