toJSON.md

February 10, 2026 ยท View on GitHub

Converter - To JSON

toJSON-file-ts toJSON-gzip-ts toJSON-brotli-ts

Description

Given an input of Readers, build (Geo|S2)JSON as an output file.

Usage

Regular JSON output

import { toJSON, JSONReader } from 'gis-tools-ts';
import { FileReader, FileWriter } from 'gis-tools-ts/file';
// or use mmap reader if using bun
// import { MMapReader } from 'gis-tools-ts/mmap';

const fileReader = new FileReader(`${__dirname}/fixtures/points.geojson`);
const jsonReader = new JSONReader(fileReader);
const bufWriter = new FileWriter(`${__dirname}/fixtures/points2.geojson`);

// store all the readers in a signle json file:
await toJSON(bufWriter, [jsonReader], { projection: 'WG', buildBBox: true });

Line Delimited JSON output

import { toJSONLD, JSONReader } from 'gis-tools-ts';
import { FileReader, FileWriter } from 'gis-tools-ts/file';
// or use mmap reader if using bun
// import { MMapReader } from 'gis-tools-ts/mmap';

const fileReader = new FileReader(`${__dirname}/fixtures/points.geojson`);
const jsonReader = new JSONReader(fileReader);
const bufWriter = new FileWriter(`${__dirname}/fixtures/points.geojsonld`);
const onFeature = (feature) => {
  feature.metadata = { id: feature.id };
  return feature;
};

// store all the readers in a signle json file:
await toJSONLD(bufWriter, [jsonReader], { projection: 'S2', buildBBox: true, onFeature });