---
sidebar:
  hidden: true
title: roboto.formats.mcap.json_decoder_factory
---
## Module Contents

### JsonDecoderFactory

```python
class roboto.formats.mcap.json_decoder_factory.JsonDecoderFactory
```

`from roboto.formats.mcap.json_decoder_factory import JsonDecoderFactory`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/json_decoder_factory.py#L61-L109)

Bases: `mcap.decoder.DecoderFactory`

Decoder factory that decodes JSON-encoded MCAP messages to the Python objects `json.loads` returns.

The SDK's own code uses it; to read messages from an MCAP file, use [`McapReader`](/docs/reference/python-sdk/roboto/formats/mcap/reader#roboto.formats.mcap.reader.McapReader) instead. Decoding uses `orjson` when the `analytics` extra installs it, and the standard library `json` module otherwise. The result is the same either way, including for the non-standard `NaN`, `Infinity`, and `-Infinity` tokens and for integers of any size.

#### JsonDecoderFactory.decoder_for()

```python
def decoder_for(
    message_encoding: str,
    schema: Optional[mcap.records.Schema],
) -> Optional[Callable[[bytes], Any]]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/json_decoder_factory.py#L70-L109)

Build a function that decodes one JSON-encoded message, or return `None` for any other encoding.

The `mcap` library's reader calls this to get a decoder for a channel's messages.

**Parameters**

- **message_encoding** (`str`): Message encoding of the channel. Only `json` gets a decoder.
- **schema** (`Optional[mcap.records.Schema]`): Ignored. JSON messages decode without a schema.

**Raises**

- `json.JSONDecodeError`: A message is not valid JSON. Raised when the returned function is called.
- `UnicodeDecodeError`: A message is not valid UTF-8. Raised when the returned function is called.

**Returns**

- `Optional[Callable[[bytes], Any]]`
