---
title: "format | JavaScript maps SDK"
description: "Documentation for MapTiler SDK"
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# Function format

-   format(style: any, space?: number): string[](#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`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) to generate formatted output.
    
    If `space` is unspecified, a default of `2` spaces will be used.
    
    #### Parameters
    
    -   style: any
        
        a MapLibre Style
        
    -   `Optional`space: number
        
        space argument to pass to `JSON.stringify`
        
    
    #### Returns string
    
    stringified formatted JSON
    
    #### Private[](#private)
    
    #### Example[](#example)
    
    ```typescript
    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));
    ```
