---
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#L76-L139)

Bases: `mcap.decoder.DecoderFactory`

Factory for creating JSON message decoders for MCAP readers.

Provides functionality to decode JSON-encoded messages within MCAP files. This decoder factory is used by the MCAP reader to handle messages that were originally encoded in JSON format.

#### 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#L84-L139)

Create a decoder function for JSON-encoded messages.

Returns a decoder function if the message encoding is JSON, otherwise returns None to indicate this factory cannot handle the encoding.

**Parameters**

- **message_encoding** (`str`): The encoding format of the message.
- **schema** (`Optional[mcap.records.Schema]`): Optional schema information for the message.

**Returns**

- `Optional[Callable[[bytes], Any]]`: A decoder function for JSON messages, or None if the encoding is not JSON.

**Usage**

```python
factory = JsonDecoderFactory()
decoder = factory.decoder_for(MessageEncoding.JSON, None)
if decoder:
    decoded = decoder(b'{"x": 1.5, "y": 2.0}')
    print(decoded)
# {'x': 1.5, 'y': 2.0}
```
