[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Type](https://evolu.dev/docs/api-reference/common/Type) › json

```ts
function json<T, Name>(
  type: T,
  name: ValidateChildTypeName<
    Name,
    BrandType<
      Type<
        "String",
        string,
        string,
        TypeOfError<"String">,
        null,
        TypeOfError<"String">,
        never,
        string,
        true
      >,
      "Json",
      JsonError
    >
  >,
  ..._validation: [JsonTypeValidationError<T>] extends [never]
    ? []
    : [ValidationFailure<JsonTypeValidationError<T>>]
): readonly [
  BrandType<
    BrandType<
      Type<
        "String",
        string,
        string,
        TypeOfError<"String">,
        null,
        TypeOfError<"String">,
        never,
        string,
        true
      >,
      "Json",
      JsonError
    >,
    Name,
    TypeError<Name> &
      TransparentTypeError & {
        error: InferErrors<T>;
      }
  >,
  (value: T["Output"]) => string & Brand<"Json"> & Brand<Name>,
  (value: string & Brand<"Json"> & Brand<Name>) => T["Output"],
];
```

Defined in: [packages/common/src/Type.ts:16723](https://github.com/evoluhq/evolu/blob/dd96d79f1dbe9a49fa12ce8e0aa7d3d0177795ca/packages/common/src/Type.ts#L16723)

Branded [Json](https://evolu.dev/docs/api-reference/common/Type/variables/Json) Type and conversions for another [Type](https://evolu.dev/docs/api-reference/common/Type/interfaces/Type).

Use this when a value must be stored as JSON text, such as in a JSON column
in an Evolu Schema. It returns a branded Json Type and functions for
converting the supplied Type's Output to and from that branded JSON
representation.

### Example

```ts
import {
  assertEqual,
  assertType,
  Age,
  NonEmptyTrimmedString100,
  json,
  object,
  type Brand,
} from "@evolu/common";

const User = object({
  name: NonEmptyTrimmedString100,
  age: Age,
});

const [UserJson, userToUserJson, userJsonToUser] = json(User, "UserJson");

const user = User.orThrow({ name: "Ada", age: 37 });
const userJson = userToUserJson(user);

assertType<typeof userJson, string & Brand<"Json"> & Brand<"UserJson">>();
assertEqual(userJson, '{"name":"Ada","age":37}');
assertEqual(UserJson.orThrow(userJson), userJson);
assertEqual(userJsonToUser(userJson), user);
```

The supplied Type must have a JSON-compatible `CanonicalInput`. The branded
Json Type accepts only valid JSON text whose parsed value can be decoded by
the supplied Type.