JSONSourcery
1 JSON Serializers
json-serializer-val
json-serializer-obj
json-serializer-struct
json-serializer?
2 Serialization
json-serializable?
serialize-json
serialize-failure?
3 JSON Object Shortcuts
json-obj
json-kv
7.7

JSONSourcery

Adrian Kant

JSONSourcery is a library built on top of the json base package in order to add automatic and manual JSON serialization in order to enable Racket values to be used directly for computation with less boilerplate needed to convert to JSON as well as adding clarifying syntax macros.

Github Repo

 (require json-sourcery) package: json-sourcery

1 JSON Serializers

syntax

(json-serializer-val predicate transformer)

 
  predicate : (-> any? boolean)
  transformer : (-> any? any?)
Create a JSON serializer for anything that passes the given predicate using the given transformer

syntax

(json-serializer-obj predicate (name accessor) ...)

 
  predicate : (-> any? boolean)
  name : id
  accessor : (-> any? any?)
Create a JSON serializer for anything that passes the given predicate using the given names and accessors to create a JSON object jsexpr

syntax

(json-serializer-struct [struct-name struct?])

Create a JSON serializer for the given struct automaticially using all fields of the structure to create a json-serializer-obj

procedure

(json-serializer? x)  boolean?

  x : any?
Predicate for JSON serializers

2 Serialization

procedure

(json-serializable? expr serializers)  boolean?

  expr : any?
  serializers : (listof json-serializer?)
Determines if the given expression is serializable with the given serializers. Errors with malformed serializers with the apropriate predicate use of accessor error

procedure

(serialize-json expr serializers)  jsexpr?

  expr : any?
  serializers : (listof json-serializer?)
Attempts to serialize the expression with the given serializers. Guaranteed to succeed on any expression that passes json-serializable? If a unserializable value is encountered, the entire function will return the symbol ’failure. Errors with malformed serializers with the apropriate predicate use of accessor error.

procedure

(serialize-failure? expr)  boolean?

  expr : any?
Semantic predicate for checking for failures (not errors) in serialize-json

3 JSON Object Shortcuts

procedure

(json-obj kv-pairs)  hash?

  kv-pairs : (listof json-kv)
A shortcut for creating JSON serializable objects with the given list of json-kv’s

procedure

(json-kv key value)  list?

  key : string?
  value : json-serializable?
A semantic shortcut for creating JSON serializable pair in a list for a JSON object. Equivalent to list.