# Parsers

> Comprehensive guide on various data format parsers including JSON5, YAML, TOML, CSV, PDF, DOCX, and token estimation for LLM.

The `parsers` object provides various parsers for common data formats.

## JSON5

[Section titled “JSON5”](#json5)

The `parsers.json5` function parses the JSON5 format. [JSON5](https://json5.org/) is an extension to the popular JSON file format that aims to be easier to write and maintain by hand (e.g. for config files).

In general, parsing a JSON file as JSON5 does not cause harm, but it might be more forgiving to syntactic errors. In addition to JSON5, [JSON repair](https://www.npmjs.com/package/jsonrepair) is applied if the initial parse fails.

* JSON5 example

```json5
{
    // comments
    unquoted: "and you can quote me on that",
    singleQuotes: 'I can use "double quotes" here',
    lineBreaks: "Look, Mom! \
No \\n's!",
    hexadecimal: 0xdecaf,
    leadingDecimalPoint: 0.8675309,
    andTrailing: 8675309,
    positiveSign: +1,
    trailingComma: "in objects",
    andIn: ["arrays"],
    backwardsCompatible: "with JSON",
}
```

To parse, use `parsers.JSON5`. It supports both a text content or a file as input.

```js
const res = parsers.JSON5("...")
```

## YAML

[Section titled “YAML”](#yaml)

The `parsers.YAML` function parses the [YAML format](/genaiscript/reference/scripts/yaml). YAML is more friendly to the LLM tokenizer than JSON and is commonly used in configuration files.

```yaml
fields:
    number: 1
    boolean: true
    string: foo
array:
    - 1
    - 2
```

To parse, use `parsers.YAML`. It supports both a text content or a file as input.

```js
const res = parsers.YAML("...")
```

## TOML

[Section titled “TOML”](#toml)

The `parsers.TOML` function parses the [TOML format](https://toml.io/). TOML is more friendly to the LLM tokenizer than JSON and is commonly used in configuration files.

```toml