No description
Find a file
2025-11-06 18:15:01 -03:00
.github/workflows CI: use nimble 0.20.1 (#137) 2025-10-14 13:26:38 +07:00
docs move chronos integration to its own module (#128) 2025-08-28 11:50:08 +02:00
fuzzer Add fuzz test 2023-12-26 16:03:47 +07:00
json_serialization Avoid write float alloc (#134) 2025-10-10 03:45:23 -03:00
tests Run tests at comptime (#139) 2025-11-06 18:15:01 -03:00
.gitignore Add fuzz test 2023-12-26 16:03:47 +07:00
config.nims Increase stack size on Windows when running CI 2024-01-01 20:07:49 +07:00
json_serialization.nim Add copyright year to source file 2023-12-25 22:55:07 +07:00
json_serialization.nimble Run tests at comptime (#139) 2025-11-06 18:15:01 -03:00
LICENSE-APACHEv2 licenses 2019-06-18 19:52:12 +02:00
LICENSE-MIT licenses 2019-06-18 19:52:12 +02:00
README.md Spec comptime tests (#133) 2025-10-08 16:11:14 -03:00

nim-json-serialization

License: Apache License: MIT Stability: experimental Github action

Introduction

nim-json-serialization is a library in the nim-serialization family for turning Nim objects into JSON documents and back. Features include:

  • Efficient coding of JSON documents directly to and from Nim data types
    • Full type-based customization of both parsing and formatting
    • Flavors for defining multiple JSON serialization styles per Nim type
    • Efficient skipping of tags and values for partial JSON parsing
  • Flexibility in mixing type-based and dynamic JSON access
    • Structured JsonValueRef node type for DOM-style access to parsed document
    • Flat JsonString type for passing nested JSON documents between abstraction layers
    • Seamless interoperability with std/json and JsonNode
  • Full RFC8259 spec compliance including the notorious JSON number
    • Passes JSONTestSuite
    • Customizable parser strictness including support for non-standard extensions
  • Well-defined handling of malformed / malicious inputs with configurable parsing limits
    • Fuzzing and comprehensive manual test coverage
  • Since v0.4.4, compile time encode/decode is supported. This means you can initialize a const value using decode. It is also ok to use it inside a static block or other Nim VM code.

Getting started

requires "json_serialization"

Create a type and use it to encode and decode JSON:

import json_serialization

type Request = object
  jsonrpc: string
  `method`: string

let
  json = """{"jsonrpc": "2.0", "method": "name"}"""
  decoded = Json.decode(json, Request)

echo decoded.jsonrpc
echo Json.encode(decoded, pretty=true)

Documentation

See the user guide.

Contributing

Contributions are welcome - please make sure to add test coverage for features and fixes!

json_serialization follows the Status Nim Style Guide.

License

Licensed and distributed under either of

or

at your option. These files may not be copied, modified, or distributed except according to those terms.