Skip to main content

JSON module · writer API

JSONWriter

Encode loaders.gl tables as JSON text, including readable GeoJSON conversion for GeoArrow WKB columns when the output needs to cross into a JSON-oriented system.

What it writes

Leave a binary table as ordinary JSON when you need to.

JSONWriter accepts row, columnar, and Arrow-backed tables and serializes them as JSON rows. GeoArrow WKB columns can be decoded to readable GeoJSON geometry by default.

Input

Row, columnar, or Arrow tables

Output

JSON text or an ArrayBuffer

Geometry

WKB to GeoJSON by default

Control

Shape, wrapper, and GeoArrow options

Detailed guide

JSONWriter reference

The sections below document usage, table conversion, GeoArrow handling, and writer options.

JSONWriter writes native Arrow tables and loaders.gl row or columnar tables as JSON text.

Usage​

import {encode} from '@loaders.gl/core';
import type {Table} from 'apache-arrow';
import {JSONWriter} from '@loaders.gl/tables/json';

declare const table: Table;

const data = await encode(table, JSONWriter); // ArrayBuffer
const text = JSONWriter.encodeTextSync(table, {json: options}); // string

Arrow table inputs are serialized as JSON row objects by default. Set json.shape: 'array-row-table' to serialize each row as an array.

If an Arrow table has a geoarrow.wkb geometry column, JSONWriter decodes that column to GeoJSON geometry objects before serializing. This keeps JSON output readable while preserving the writer's normal array-of-rows shape.

const json = await encode(geoArrowTable, JSONWriter);
// [{"name":"A","geometry":{"type":"Point","coordinates":[1,2]}}]

Set json.geoarrow: 'none' to serialize the raw WKB values instead.

Data Format​

Encoded batches are array buffers or strings.

JSONWriter Options​

OptionTypeDefaultDescription
json.shape'object-row-table' | 'array-row-table''object-row-table'Requested JSON row shape.
json.geoarrow'auto' | 'none''auto'Controls GeoArrow WKB decoding. 'auto' decodes geoarrow.wkb columns to GeoJSON geometry objects. 'none' serializes the raw values.
json.wrapper(table: RowObject[] | RowArray[]) => unknownWraps the encoded table rows in a custom JSON value.