NathanReb / ppx_yojson

OCaml PPX extension for JSON literals and patterns
BSD 2-Clause "Simplified" License
42 stars 5 forks source link

v1.0.0 #1

Closed NathanReb closed 5 years ago

NathanReb commented 6 years ago

Internals

Features

Antiquotations for expressions

We want this:

let json =
  let s = `String "s" in
  [%yojson {a = [%y s]; b = 2}]

to be rewritten as:

let json =
  let s = `String "s" in
  `Assoc [("a", s); ("b", `Int 2)]

Antiquotations for patterns

We want this:

match json with
| [%yojson? [%y? `String s]] -> s
| [%yojson? {a = [%y? a]; b = [%y? `Int b]}] ->
  Printf.sprintf "%s and %d" (Yojson.Safe.to_string a) b

to be rewritten as:

match json with
| `String s -> s
| `Assoc [("a", a); ("b", `Int b)] ->
  Printf.sprintf "%s and %d" (Yojson.Safe.to_string a) b