polytropos-aeson: High-performance aeson JSON codecs for polytropos open records and variants

[ data, json, library ] [ Propose Tags ] [ Report a vulnerability ]

Linear O(N) Data.Aeson.ToJSON and Data.Aeson.FromJSON serialization codecs for polytropos open records and variants via aeson.

Unlike GHC.Generics which builds intermediate binary tree nodes during serialization, polytropos-aeson unrolls the flat contiguous Data.Primitive.SmallArray.SmallArray payload directly into a JSON object and back. Variants serialize into tagged JSON objects with O(1) tag dispatch.

Start at the front door module Polytropos.Aeson for complete documentation, codec options, and worked examples.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.2
Change log CHANGELOG.md
Dependencies aeson (>=2.0 && <2.3), base (>=4.14 && <5), bytestring (>=0.10 && <0.13), polytropos-core (>=0.1 && <0.2), polytropos-plugin (>=0.1 && <0.2), text (>=1.2 && <2.2) [details]
License (EUPL-1.2 OR Apache-2.0)
Author Nadia Yvette Chambers
Maintainer nadia.yvette.chambers@ik.me
Uploaded by nyc at 2026-10-21T21:34:26Z
Category Data, JSON
Home page https://github.com/NadiaYvette/polytropos
Bug tracker https://github.com/NadiaYvette/polytropos/issues
Source repo head: git clone https://github.com/NadiaYvette/polytropos(packages/polytropos-aeson)
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 3 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-10-22 [all 1 reports]

Readme for polytropos-aeson-0.1.0.2

[back to package description]

polytropos-aeson

High-performance aeson JSON serialization and deserialization codecs for polytropos open records and variants.

Overview

Unlike GHC.Generics which builds intermediate binary tree nodes ((:*:), (:+:)) during serialization, polytropos-aeson unrolls the flat contiguous SmallArray payload directly into JSON objects and back. Open variants serialize into tagged JSON objects with \(O(1)\) tag dispatch.

Features

  • Heterogeneous Record Encoding & Decoding: Automatic ToJSON and FromJSON instances for Record r via compile-time field unrolling.
  • Tagged Variant Codecs: Fast \(O(1)\) constructor dispatch encoding variants as {"tag": "Ctor", "contents": payload}.
  • Homogeneous Fast Path: Specialized introspection and codec paths for homogeneous records.

Quick Example

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# OPTIONS_GHC -fplugin=Polytropos.Plugin #-}

import Data.Aeson (encode, decode)
import Polytropos
import Polytropos.Aeson ()

type Config = Record '[ "host" := String, "port" := Int ]

main :: IO ()
main = do
  -- Direct serialization without ($) grouping:
  let cfg = REC { host = "localhost", port = 8080 } :: Config
  print (encode cfg)

  -- Functional record update without parentheses:
  let prodCfg = REC_UPD cfg { host = "prod.internal" }
  print (encode prodCfg)

License

Dual-licensed under EUPL-1.2 OR Apache-2.0.