Json serialization typeclass #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
This file provides helpers for serializing primitive types to json.
@[derive non_null_json_serializable]
will make any structure json serializable; for instance,
@[derive non_null_json_serializable]
structure my_struct :=
(success : bool)
(verbose : ℕ := 0)
(extras : option string := none)
can parse {"success": true}
as my_struct.mk true 0 none
, and reserializing give
{"success": true, "verbose": 0, "extras": null}
.
Main definitions #
json_serializable
: a typeclass for objects which serialize to jsonjson_serializable.to_json x
: convertx
to jsonjson_serializable.of_json α j
: readj
in as anα