package awsm-codegen

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

Module Awsm_codegen.Json_parserSource

Sourcetype 'a t

A parser returning a value of type 'a.

It can act on a JSON value using the run function.

Sourceval run : 'a t -> Json.t -> ('a, string) Core.Result.t

Run the parser against a JSON value. The Error case contains information about where an error occured in the JSON document.

Sourceval run_exn : 'a t -> Json.t -> 'a
Sourceval parse_with : (Json.t -> ('a, string) Core.Result.t) -> 'a t

Low-level way to define a parser. Prefer combining other functions from this module, as it will return better error messages.

When returning an error, only include the error message: the location data will be added automatically by this module.

Sourceval (>>|) : 'a t -> ('a -> 'b) -> 'b t

Map over a parser.

Sourceval map_result : 'a t -> f:('a -> ('b, string) Core.result) -> 'b t

Map over a parser, with a function that can return an error.

Sourceval string : string t

Convert a string.

Sourceval int : int t

Convert an int. Fails if a number is not exactly an integer.

Sourceval float : float t
Sourceval int64 : int64 t

Convert an int64. Fails if a number is not exactly an int64.

Sourceval bool : bool t

Convert a bool.

Sourceval list : 'a t -> 'a list t

Convert a list of values.

Sourceval dict : 'a t -> (string * 'a) list t

Convert an homogeneous dictionary. It is an object where all values have the same type. For example, {"x": 1, "y": 2, "z": 3} can be parsed using dict int to [("x", 1); ("y", 2); ("z", 3)].

Sourcetype 'a record

An abstract value representing values in a JSON record. To parse such a record, use record.

Sourceval return : 'a -> 'a record

Create a record that contains a static value.

Sourcemodule Let_syntax : sig ... end

Applicative interface for record. The ppx_let syntax extension uses this to translate let%map x1 = v1 and x2 = v2 in e.

Sourceval field : string -> 'a t -> 'a record

A required field. If not present, will return an error.

Sourceval field_opt : string -> 'a t -> 'a option record

An optional field. If not present, will return None.

Sourceval field_or : string -> 'a t -> default:'a -> 'a record

Like field_opt, but will return default if the field is not present.

Sourceval field_ignored : string -> unit record

Ignore this field. This completely ignores the presence, type and value of this field. It is usually better to parse the field with its correct type, and ignore it in the calling code.

Sourceval record : 'a record -> 'a t

Parse a JSON record. In addition to returning the correct data, it will also check that all fields in the record have been parsed explicitly.

Sourceval record_or_list_of : 'a record -> 'a list t

If the JSON value being parsed is a record, parse it (and return a singleton). If it is a list, parse a list of records.

Sourceval field_based : string -> (string -> 'a record option) -> 'a t

Support for type/value objects. field_based key get_parser will parse the current JSON value as an object, inspect the string value at the given key, and pass it to get_parser. The return value of this function determines how the rest of the record will be parsed.

Sourceval if_field_present : string -> then_:'a record -> else_:'a record -> 'a record

Parse using a different function depending on whether a key is present.

OCaml

Innovation. Community. Security.