Chevron Down
Table of Contents
Chevron DownAPI Reference

JSONLoader

Streaming loader for JSON encoded files.

LoaderCharacteristic
File Extension.json,
File TypeText
File FormatJSON
Data FormatClassic Table
Supported APIsload, parse, parseSync, parseInBatches

Usage

import {JSONLoader} from '@loaders.gl/json';
import {load} from '@loaders.gl/core';

const data = await load(url, JSONLoader, {json: options});

The JSONLoader supports streaming JSON parsing, in which case it will yield "batches" of rows from the first array it encounters in the JSON. To e.g. parse a stream of GeoJSON:

import {JSONLoader} from '@loaders.gl/json';
import {load} from '@loaders.gl/core';

const data = await loadInBatches('geojson.json', JSONLoader);

for await (const batch of batches) {
  // batch.data will contain a number of rows
  for (const feature of batch.data) {
    switch (feature.geometry.type) {
      case 'Polygon':
      ...
    }
  }
}

Options

OptionTypeDefaultDescription
json.tableBooleanTBDParse JSON as table, i.e. return the first embedded array in the JSON.

Attribution

This loader is based on a fork of dscape's clarinet under BSD 2-clause license.