Skip to content

Releases: melange-community/jsonkit

jsonkit.1.1.0

Choose a tag to compare

@pedrobslisboa pedrobslisboa released this 17 Sep 12:29
  • Fix the of_json deriver for polymorphic variants with inherited rows, on
    both backends. Decoding now tries, in this order: the type's own tags, then
    the inherited types (in definition order), then the [@json.catch_all] row,
    then the error (or [@json.allow_any]). It no longer depends on the row
    order in the definition: an inherited type listed before an own tag used to
    shadow it on Melange, and an own catch-all used to swallow every tag of the
    inherited types on both backends.
  • Fix: use the len value as an expression on the variant case function to avoid
    expected "named" value to be declared on the function.
  • Fix: remove the duplicated runtime deps from the ppx libraries.
  • Move the JSON Schema runtime into the main packages, at Jsonkit.Jsonschema.
    It is the same API under a new path, on both backends, so sources shared
    between a native and a Melange build need no per-backend conditionals. The
    JSON runtime is unchanged and stays where it is: everything previously at
    Jsonkit.* is still at Jsonkit.*, and is now also reachable as
    Jsonkit.Json.*.
  • Deprecate the jsonkit.jsonschema and
    jsonkit-melange.jsonschema libraries, along with the
    Ppx_deriving_jsonschema_runtime, Ppx_deriving_jsonschema_runtime_classify
    and Ppx_deriving_jsonschema_runtime_primitives modules. They still exist and
    still work, as aliases for Jsonkit.Jsonschema, Jsonkit.Jsonschema.Classify
    and the primitives modules. The deprecated modules keep their old shape:
    Primitives still has its Yojson and Jsonkit submodules, and
    json_schema is still there under that name, so existing code compiles
    unchanged.

jsonkit.1.0.0

Choose a tag to compare

@pedrobslisboa pedrobslisboa released this 30 Jul 18:12

Rename the project from melange-json to jsonkit. The derivers, the runtime and the JSON Schema support all behave the same on native OCaml and on Melange, so the packages no longer lead with Melange branding: the native package takes the plain name, and the Melange package carries the suffix.

  • melange-json-native → jsonkit, melange-json-native.ppx → jsonkit.ppx
  • melange-json → jsonkit-melange, melange-json.ppx → jsonkit-melange.ppx
  • module Melange_json → Jsonkit

The exposed module is Jsonkit on both backends, so sources shared between a
native and a Melange build need no per-backend conditionals. These are new
opam packages, so numbering restarts: jsonkit 1.0.0 supersedes
melange-json 2.0.0 and contains everything in it, despite the lower number.

The melange-json packages will not be updated further. (#107)

Changes:

  • PPX: Creates a linter to warn about the wrong usage of [@json.name] on record fields
    and [@json.key] on variant constructors.
  • PPX: Adds a linter that catches namespaced json.* field attributes
    ([@json.name], [@json.key], [@json.default], etc.) on
    [@@deriving json, jsonschema] types, to use [@name],
    [@key], [@default], [@option] instead.
  • jsonschema: Remove the ~variant_as_string flag; use
    [@@jsonschema.compact_variants] to render payload-free constructors as
    plain string constants.
  • PPX: Respect the [@json.name "..."] attribute in of_json error
    messages.
  • PPX: Ignore extra JSON object fields by default in the native
    PPX, matching the Melange PPX. Add [@json.disallow_extra_fields] for
    records and inline records that should reject unknown keys.
  • PPX: [@@deriving jsonschema] now generates
    "additionalProperties": true for records by default, matching the JSON
    derivers which ignore unknown object keys. Add
    [@@jsonschema.disallow_extra_fields] (and
    [@jsonschema.disallow_extra_fields] on inline records in variants) to opt
    back into strict objects ("additionalProperties": false).
    [@@jsonschema.allow_extra_fields] is still accepted for backwards
    compatibility but is now a no-op; combining it with disallow_extra_fields
    is rejected.
  • Library: Add Jsonkit.unknown_variant_case, a record type with
    fields tag : string and payload : Jsonkit.t list option,
    meant to be referenced as the argument of a catch-all constructor (see
    next entry). Companion JSON-schema literal
    Jsonkit.unknown_variant_case_jsonschema plugs into
    ppx_deriving_jsonschema.
  • PPX: Add [@json.catch_all] attribute, marking a constructor as the
    catch-all for any unrecognised string tag. The constructor's argument
    is Jsonkit.unknown_variant_case; payload distinguishes bare
    strings (None) from array forms (Some xs), preserving the wire
    shape for round-trip-faithful decoding/encoding even when a future
    producer adds payload-bearing variants. Works on both classic variants
    and polymorphic variants. Pairs naturally with
    [@@json.compact_variants].
  • PPX: Add [@@json.compact_variants] attribute for variant and polyvariant
    types. Encodes constructors without arguments as plain JSON strings and
    constructors with arguments as JSON arrays ["ConstructorName", arg1, ...].
    The decoder now also accepts ["Tag"] (singleton array) as equivalent to
    "Tag" for nullary constructors, making the compact form a strict superset
    of the standard array encoding.
  • Support Ptype_open, e.g. type u = X.(x) [@@deriving json]
    (#60)
  • Add support for [@drop_default] with [@default] to omit fields
    from JSON output when their value matches the default. Equality is
    resolved via equal_<type> functions in scope by default, but a custom comparison
    function can be provided directly, e.g. [@json.drop_default Int.equal]
    (#77)
  • Add Jsonkit.equal for comparing two JSON values, and
    [@drop_default_if_json_equal] as an alternative to [@json.drop_default]
    that compares values at the JSON level
    (#77)
  • PPX: Fix unused-var warning with polyvars without own cases
    (#38)
  • PPX: Add support for labeled tuples, e.g. [%to_json: a:string * b:int],
    encoded as JSON objects like records

2.0.0

Choose a tag to compare

@jchavarri jchavarri released this 11 Mar 10:14

CHANGES:

  • [breaking] Library, PPX: Unify runtimes (*.ppx-runtime libraries are
    removed, can use melange-json and melange-json-native instead), replace
    Json module with Melange_json, deprecate Decode and Encode modules,
    introduce new decoding error type and helper function
    of_json_error_to_string.
    (#36)
  • [breaking] PPX: Code to decode polyvariants doesn't use an additional
    _poly function which was also generated by the PPX. Instead
    Unexpected_variant error is used to signal that next decoder should be
    tried. (#32)
  • [breaking] Json.Decode.DecodeError exception now contains a variant type
    as payload instead of a string.
    (#32)
  • [breaking] PPX: Rename [@json.as] to [@json.name]
    (#23)
  • [breaking] PPX: Drop special encoding for enumeration-like variants
    (variants with each constructor having no arguments).
    (#26)
  • [breaking] PPX: change JSON representation of polyvariants, make it
    compatible with ppx_deriving_yojson and ppx_yojson_conv
    (#27)
  • [breaking] PPX: Consistent use of exceptions in runtime.
    (#28)
  • PPX: [@@deriving json] now can be used within signatures (this includes
    .mli files).
    (#32)
  • PPX: Add runtime for result
    (#13)
  • PPX: Add yojson as runtime dep for the native version
    (#15)
  • PPX: add [@@json_string] for deriving converters to/from JSON strings
    directly (#30)
  • PPX: add support for int64 in the runtime
    (#33)
  • PPX: remove string_to_json usage on js side
    (#35)
  • PPX: Add array functions to native runtime
    (#37)

1.3.0

Choose a tag to compare

@jchavarri jchavarri released this 28 Aug 08:53

CHANGES:

  • PPX: Qualify usages of infix operators with Stdlib
    (#11)
  • Add melange-json-native package
    (#12)

1.2.0

Choose a tag to compare

@jchavarri jchavarri released this 16 Aug 10:27

CHANGES:

  • Port PPX from @andreypopp/ppx_deriving_json
    (#10)

1.1.0

Choose a tag to compare

@anmonteiro anmonteiro released this 03 Feb 23:12
5f884a5

CHANGES:

  • Require Melange v3 (#6)

1.0.0

Choose a tag to compare

@anmonteiro anmonteiro released this 10 Oct 02:38
c3c70a6

CHANGES:

  • Initial release