On this page

Function format

  • Format a MapLibre Style. Returns a stringified style with its keys sorted in the same order as the reference style.

    The optional space argument is passed to JSON.stringify to generate formatted output.

    If space is unspecified, a default of 2 spaces will be used.

    Parameters

    • style: any

      a MapLibre Style

    • Optionalspace: number

      space argument to pass to JSON.stringify

    Returns string

    stringified formatted JSON

    var fs = require('fs');
    var format = require('maplibre-gl-style-spec').format;
    var style = fs.readFileSync('./source.json', 'utf8');
    fs.writeFileSync('./dest.json', format(style));
    fs.writeFileSync('./dest.min.json', format(style, 0));
    
Was this helpful?
SDK JS
Reference
format