Function json5format::format
source · pub fn format(
buffer: &str,
filename: Option<String>,
options: Option<FormatOptions>,
) -> Result<Vec<u8>, Error>
Expand description
Format a JSON5 document, applying a consistent style, with given options.
See FormatOptions for style options, and confirm the defaults by
reviewing the source of truth via the src
link for
impl Default for FormatOptions.
§Format and Style (Default)
Unless FormatOptions are modified, the JSON5 formatter takes a JSON5 document (as a unicode String) and generates a new document with the following formatting:
- Indents 4 spaces.
- Quotes are removed from property names if they are legal ECMAScript 5.1 identifiers. Property names that do not comply with ECMAScript identifier format requirements will retain their existing (single or double) quotes.
- All property and item lists end with a trailing comma.
- All property and item lists are broken down; that is, the braces are on separate lines and all values are indented.
{
key: "value",
array: [
3.145,
]
}
§Arguments
- buffer - A unicode string containing the original JSON5 document.
- filename - An optional filename. Parsing errors typically include the filename (if given), and the line number and character column where the error was detected.
- options - Format style options to override the default style, if provided.
§Returns
- The formatted result in UTF-8 encoded bytes.