# XO0433: a mistyped `to:` or `from:` of `derive Json(via: ...)`

`to` converts the value to its `via` type P and cannot fail. `from` converts a decoded P back; it may fail, and its error's Display text becomes the decode error's message at the value's path (`at $.legs[1].amount: invalid amount "12.3.4"`), so the error type must implement Display. Change the function's parameter or result to T and P, or give the error a `display` method. See core 2.3 and decision 0478.

## Example

```xo
struct Money {
  minor: Int
} derive Json(via: Int, to: money_minor, from: money_of)

fn money_minor(m: Money) -> Str { "${m.minor}" }

fn money_of(n: Int) -> Money { Money{minor: n} }
```

## Fix

```xo
struct Money {
  minor: Int
} derive Json(via: Int, to: money_minor, from: money_of)

fn money_minor(m: Money) -> Int { m.minor }

fn money_of(n: Int) -> Money { Money{minor: n} }
```

Run `xo explain XO0433` for this text in a terminal, or see
[section 10.6 of the specification](../../spec/core/#106-diagnostic-codes).

