package orsetto

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

JavaScript Object Notation (JSON) output formatter.

Overview

Specialization of

f_emit

to output texts in the JSON format. Combinators are provided for the basic JSON types to be used for directly emitting application data as JSON text. Additional conveniences are provided for emitting encapsulated JSON values as text.

Type
type 'a t = private 'a Cf_emit.To_formatter.t

The type of JSON emitters.

Basic Emitters
val null : unit t

The emitter for the JSON null literal

val boolean : bool t

The emitter for JSON boolean values.

val integer : int t

The emitter for integers as JSON numeric values.

val float : float t

The emitter for floats as JSON numeric values.

val string : Ucs_text.t t

The emitter for Unicode texts as JSON string literals.

val array : ('a -> unit t Seq.t) -> 'a t

Use array f to make an emitter for values represented as JSON arrays. Applies the emitted value to f and elaborates the returned sequence of sealed emitters as a JSON array.

val objval : ('a -> (Ucs_text.t * unit t) Seq.t) -> 'a t

Use objval f to make an emitter for values represented as JSON objects. Applies the emitted value to f and elaborates the returned sequence of key/value pairs as a JSON object. The value of each field is a sealed emitter.

val value : Cf_type.opaque t

The emitter for opaque values. Raises Invalid_argument if the opaque value was not witnessed with a type compatible with JSON encoding.

Utility
val to_text : Cf_type.opaque -> Ucs_text.t

Use to_text v to format v as a Unicode text. Raises Invalid_argument if v was not witnessed with a type compatible with JSON encoding.

OCaml

Innovation. Community. Security.