yamson

2026-11-29

Fast YAML and JSON parsers for Common Lisp.

Upstream URL

github.com/bohonghuang/yamson

Author

Bohong Huang <bohonghuang@qq.com>

Maintainer

Bohong Huang <bohonghuang@qq.com>

License

Apache-2.0
README
Yamson

A high-performance YAML/JSON parser for Common Lisp.

1Features

  • Full-featured \\Yamson aims to comply with YAML 1.2 (only parsing, no serialization,but contributions are welcome), while also supporting fast JSONparsing in a subset mode.

    Almost all YAML 1.2 features have been implemented, with a few incompatibilities.

  • High performance \\Yamson can parse YAML at speeds around 50MB/s and JSON at over100MB/s on Intel® Core™ i7-11700K with SBCL.
  • Low memory footprint \\Yamson is optimized for memory usage during parsing, reducingunnecessary byte consing and GC pressure, making it suitable forreal-time applications (such as game development).
  • Highly portable \\Yamson is theoretically compatible with any ANSI-conformingimplementation, and has been tested to work on SBCL, CCL, ECL,Clasp, and CLISP.
  • Minimal dependencies \\Yamson has very few dependencies and does not rely on foreignlibraries such as libyaml.
  • Streaming parsing support \\Input doesn't need to be fully loaded into memory in the firstplace, improving memory efficiency in scenarios such as reading fromfiles.

2Installation

Yamson and its dependencies are not yet available on Quicklisp. Youwill need to manually clone them into the local-projects directoryunder your Quicklisp installation.

Yamson depends on:

3Usage

  CL-USER> (yamson:parse "
  key:
  - value1
  - value2")
  (("key" "value1" "value2"))

  CL-USER> (yamson:parse "
  ---
  key: [&1 value, *1]
  ---
  ..." :mode :yaml-multidoc)
  ((("key" "value" "value")) :NULL)

  CL-USER> (yamson:parse "
  a: 1
  b: 2
  c: 3")
  (("a" . 1) ("b" . 2) ("c" . 3))

  CL-USER> (yamson:parse "
  a: 1
  b: 2
  c: 3" :mapping (alexandria:rcurry #'alexandria:alist-hash-table :test #'equal))
  #<HASH-TABLE :TEST EQUAL :COUNT 3 {1202B6CAD3}>

  CL-USER> (yamson:parse "
  - ~
  - null
  - " :sequence (lambda (list) (coerce list 'simple-vector)) :null (constantly (vector)))
  #(#() #() #())

  CL-USER> (yamson:parse "{\"a\":1} ..." :mode :json :junk-allowed t)
  (("a" . 1))

  CL-USER> (yamson:parse "!intern SYMBOL" :tags (list (lambda (tag value) (when (string= tag "intern") (values (intern value) t)))))
  SYMBOL

4Incompatibilities with YAML 1.2

The following are known implemented features that are incompatiblewith the YAML 1.2 specification:
  1. Anchors or tags cannot be applied to a sequence at the sameindentation level as its parent mapping:
         object: !!seq
         - 1
         - 2
         - 3
    

    To work around this, you must indent the sequence to the next level:

         object: !!seq
           - 1
           - 2
           - 3
    
  2. Tags do not influence how the parser interprets the subsequentobject. For example:
         !!str 1e3
    

    This will yield ~"1000.0"~ instead of ~"1e3"~ , since 1e3 is first parsed as a number and then converted to a string.

  3. It is not possible to create a self-referential structure usinganchors and aliases. For example:
         &1 [1, 2, 3, *1]
    

    This fails because &1 does not take effect until after [1, 2, 3, *1] has been fully parsed.

Dependencies (3)

  • alexandria
  • parachute
  • parsonic

Dependents (0)

    • GitHub
    • Quicklisp