The trivial-json-codec Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The trivial-json-codec Reference Manual

This is the trivial-json-codec Reference Manual, version 0.3.10, generated automatically by Declt version 2.4 patchlevel 1 "Will Decker" on Mon Jul 29 16:50:54 2019 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

Trivial JSON Codec Manual

[in package TRIVIAL-JSON-CODEC]

pipeline status Quicklisp

Description

A JSON parser able to handle class hierarchies.

Limitations: It expects the classes of the hierarchy to have at least one slot named differently. It does not fully follow the JSON specification.

Lists are serialized different than arrays:

(trivial-json-codec:serialize-json '(1 2 3 4))
=> "<1,2,3,4>"

(trivial-json-codec:serialize-json (make-array (1) :initial-contents '(1 2 3 4)))
=> "[1,2,3,4]"

Installing trivial-json-codec

This project is available in the latest QuickLisp distribution, so installing it is reduced to calling:

(ql:quickload :trivial-json-codec)

Working Example

The following code demonstrates the use-case for this library.

Note: The sequence '=>' indicates the result from evaluating the previous expression.

(defclass Payload ()
  ())

(defclass SimplePayload (Payload)
  ((value :type integer
          :initarg :value)))

(defclass ComplicatedPayload (Payload)
  ((value :type string
          :initarg :value)
   (additional-info :type string
		    :initarg :additional-info)
   (message-id :type trivial-utilities:positive-fixnum
	       :initarg :message-id)))

(defclass DifferentPayload (Payload)
  ((cargo :type fixnum
          :initarg :cargo)))

(defclass Message ()
  ((uid :initarg :uid
	:initform nil
	:accessor uid)
   (payload :type (or null Payload)
	    :initarg :payload
	    :accessor payload)))

(c2mop:ensure-finalized (find-class 'Payload))
(c2mop:ensure-finalized (find-class 'SimplePayload))
(c2mop:ensure-finalized (find-class 'ComplicatedPayload))
(c2mop:ensure-finalized (find-class 'DifferentPayload))
(c2mop:ensure-finalized (find-class 'Message))

(let ((message (make-instance 'Message :uid 1 :payload (make-instance 'Simplepayload :value 12345))))
  (trivial-json-codec:serialize-json message))
=> "{ \"UID\" : 1,  \"PAYLOAD\" : { \"VALUE\" : 12345}}"

(deserialize-json "{ \"UID\" : 1,  \"PAYLOAD\" : { \"VALUE\" : 12345}}" :class (find-class 'Message))
=> #<MESSAGE> with a payload of type SimplePayload


(let ((message (make-instance 'Message :uid 2 :payload (make-instance 'ComplicatedPayload :value "abc" :message-id 17 :additional-info "1234"))))
  (trivial-json-codec:serialize-json message))
=> "{ \"UID\" : 2,  \"PAYLOAD\" : { \"VALUE\" : \"abc\",  \"ADDITIONAL-INFO\" : \"1234\",  \"MESSAGE-ID\" : 17}}"

(deserialize-json "{ \"UID\" : 2,  \"PAYLOAD\" : { \"VALUE\" : \"abc\",  \"ADDITIONAL-INFO\" : \"1234\",  \"MESSAGE-ID\" : 17}}" :class (find-class 'Message))
=> #<MESSAGE> with a payload of type ComplicatedPayload

(let ((message (make-instance 'Message :uid 2 :payload (make-instance 'DifferentPayload :cargo -147))))
  (trivial-json-codec:serialize-json message))
=> "{ \"UID\" : 2,  \"PAYLOAD\" : { \"CARGO\" : -147}}"

(deserialize-json "{ \"UID\" : 2,  \"PAYLOAD\" : { \"CARGO\" : -147}}" :class (find-class 'Message))
=>  #<MESSAGE> with a payload of type DifferentPayload


Due to the known limitation mentioned in the description, the following is NOT possible:

(defclass StringPayload (Payload)
  ((value :type string
          :initarg :value)))

(let ((message (make-instance 'Message :uid 2 :payload (make-instance 'StringPayload :value "abc"))))
  (trivial-json-codec:serialize-json message))
=> "{ \"UID\" : 2,  \"PAYLOAD\" : { \"VALUE" : \"abc\"}}"

(deserialize-json "{ \"UID\" : 2,  \"PAYLOAD\" : { \"VALUE" : \"abc\"}}" :class (find-class 'Message))
=> This terminates with an error due to non-unique class mapping. StringPayload and Simplepayload differ only on the slot's type.

Exported Symbols

License Information

This library is released under the MIT License. Please refer to the LICENSE to get the full licensing text.

Contributing to this project

Please refer to the CONTRIBUTING document for more information.


Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 trivial-json-codec

Author

Eric Diethelm <ediethelm@yahoo.com>

License

MIT

Description

A JSON parser able to identify class hierarchies.

Long Description
Version

0.3.10

Dependencies
Source

trivial-json-codec.asd (file)

Components

Next: , Previous: , Up: Top   [Contents][Index]

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.1 trivial-json-codec.asd

Location

trivial-json-codec.asd

Systems

trivial-json-codec (system)


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.2 trivial-json-codec/package.lisp

Parent

trivial-json-codec (system)

Location

package.lisp

Packages

trivial-json-codec


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.3 trivial-json-codec/trivial-json-codec.lisp

Parent

trivial-json-codec (system)

Location

trivial-json-codec.lisp

Exported Definitions
Internal Definitions

Previous: , Up: Lisp files   [Contents][Index]

3.1.4 trivial-json-codec/documentation.lisp

Parent

trivial-json-codec (system)

Location

documentation.lisp

Exported Definitions

Next: , Previous: , Up: Top   [Contents][Index]

4 Packages

Packages are listed by definition order.


Previous: , Up: Packages   [Contents][Index]

4.1 trivial-json-codec

trivial-json-codec provides a JSON parser able to identify class hierarchies.

Source

package.lisp (file)

Use List
Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Exported definitions


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.1 Special variables

Special Variable: @trivial-json-codec-contributing
Package

trivial-json-codec

Source

documentation.lisp (file)

Special Variable: @trivial-json-codec-description
Package

trivial-json-codec

Source

documentation.lisp (file)

Special Variable: @trivial-json-codec-example
Package

trivial-json-codec

Source

documentation.lisp (file)

Special Variable: @trivial-json-codec-exported
Package

trivial-json-codec

Source

documentation.lisp (file)

Special Variable: @trivial-json-codec-installing
Package

trivial-json-codec

Source

documentation.lisp (file)

Special Variable: @trivial-json-codec-license
Package

trivial-json-codec

Source

documentation.lisp (file)

Special Variable: @trivial-json-codec-manual
Package

trivial-json-codec

Source

documentation.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.2 Functions

Function: deserialize-json JSON-STR &key CLASS READ-TABLE CONSTRUCTORS

Reads *JSON-STR* and creates an according object.
If *CLASS* is non-nil and represents a class, an instance of it is returned. Otherwise only built-in types can be deserialized.
*READ-TABLE* makes it possible to inject specific readers, as pondons to *SERIALIZE*. It has the form of an alist containing the dispatch character as car and the deserialization function as cdr. *CONSTRUCTORS* holds an alist mapping the keyword returned by a specific reader to a object construction function.

Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)

Function: deserialize-raw JSON-STR &key READ-TABLE

Deserialize *JSON-STR* into a property list. As opposed to *DESERIALIZE-JSON* this function does not require a base class to deserialize.

Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)

Function: read-array JSON START-POSITION &key OPEN-CHAR CLOSE-CHAR
Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)

Function: read-number JSON START-POSITION
Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)

Function: read-string JSON START-POSITION
Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)

Function: serialize-json OBJ

Takes *OBJ* and serializes it into a string. Uses the generic *SERIALIZE* to do the job.

Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)


Previous: , Up: Exported definitions   [Contents][Index]

5.1.3 Generic functions

Generic Function: serialize OBJ STREAM

Serialize an object *OBJ* into *STREAM*.
Implementations for built-in types already exist. The user might extend with methods for specific types.

Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)

Methods
Method: serialize (OBJ standard-object) STREAM
Method: serialize (OBJ symbol) STREAM
Method: serialize (OBJ array) STREAM
Method: serialize (OBJ list) STREAM
Method: serialize (OBJ float) STREAM
Method: serialize (OBJ integer) STREAM
Method: serialize (OBJ string) STREAM
Method: serialize (OBJ (eql t)) STREAM
Method: serialize (OBJ function) STREAM
Method: serialize (OBJ (eql nil)) STREAM

Previous: , Up: Definitions   [Contents][Index]

5.2 Internal definitions


Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Functions

Function: consume JSON JSON-START-POSITION READ-TABLE

Consumes one element from the beginning of the string and returns the values (produced-element consumed-until).

Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)

Function: create-object-from-json PARSED BASE-CLASS CONSTRUCTORS
Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)

Function: create-symbol-from-json PARSED BASE-CLASS CONSTRUCTORS
Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)

Function: parse-array JSON START-POSITION OPEN-CHAR READ-TABLE
Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)

Function: parse-keyvalue JSON START-POSITION JSON-END-POSITION READ-TABLE
Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)

Function: parse-object JSON START-POSITION READ-TABLE
Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)

Function: read-false JSON START-POSITION
Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)

Function: read-null JSON START-POSITION
Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)

Function: read-true JSON START-POSITION
Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)

Function: skip-blanks STR START END
Package

trivial-json-codec

Source

trivial-json-codec.lisp (file)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   F   L   T  
Index Entry  Section

F
File, Lisp, trivial-json-codec.asd: The trivial-json-codec<dot>asd file
File, Lisp, trivial-json-codec/documentation.lisp: The trivial-json-codec/documentation<dot>lisp file
File, Lisp, trivial-json-codec/package.lisp: The trivial-json-codec/package<dot>lisp file
File, Lisp, trivial-json-codec/trivial-json-codec.lisp: The trivial-json-codec/trivial-json-codec<dot>lisp file

L
Lisp File, trivial-json-codec.asd: The trivial-json-codec<dot>asd file
Lisp File, trivial-json-codec/documentation.lisp: The trivial-json-codec/documentation<dot>lisp file
Lisp File, trivial-json-codec/package.lisp: The trivial-json-codec/package<dot>lisp file
Lisp File, trivial-json-codec/trivial-json-codec.lisp: The trivial-json-codec/trivial-json-codec<dot>lisp file

T
trivial-json-codec.asd: The trivial-json-codec<dot>asd file
trivial-json-codec/documentation.lisp: The trivial-json-codec/documentation<dot>lisp file
trivial-json-codec/package.lisp: The trivial-json-codec/package<dot>lisp file
trivial-json-codec/trivial-json-codec.lisp: The trivial-json-codec/trivial-json-codec<dot>lisp file

Jump to:   F   L   T  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   C   D   F   G   M   P   R   S  
Index Entry  Section

C
consume: Internal functions
create-object-from-json: Internal functions
create-symbol-from-json: Internal functions

D
deserialize-json: Exported functions
deserialize-raw: Exported functions

F
Function, consume: Internal functions
Function, create-object-from-json: Internal functions
Function, create-symbol-from-json: Internal functions
Function, deserialize-json: Exported functions
Function, deserialize-raw: Exported functions
Function, parse-array: Internal functions
Function, parse-keyvalue: Internal functions
Function, parse-object: Internal functions
Function, read-array: Exported functions
Function, read-false: Internal functions
Function, read-null: Internal functions
Function, read-number: Exported functions
Function, read-string: Exported functions
Function, read-true: Internal functions
Function, serialize-json: Exported functions
Function, skip-blanks: Internal functions

G
Generic Function, serialize: Exported generic functions

M
Method, serialize: Exported generic functions
Method, serialize: Exported generic functions
Method, serialize: Exported generic functions
Method, serialize: Exported generic functions
Method, serialize: Exported generic functions
Method, serialize: Exported generic functions
Method, serialize: Exported generic functions
Method, serialize: Exported generic functions
Method, serialize: Exported generic functions
Method, serialize: Exported generic functions

P
parse-array: Internal functions
parse-keyvalue: Internal functions
parse-object: Internal functions

R
read-array: Exported functions
read-false: Internal functions
read-null: Internal functions
read-number: Exported functions
read-string: Exported functions
read-true: Internal functions

S
serialize: Exported generic functions
serialize: Exported generic functions
serialize: Exported generic functions
serialize: Exported generic functions
serialize: Exported generic functions
serialize: Exported generic functions
serialize: Exported generic functions
serialize: Exported generic functions
serialize: Exported generic functions
serialize: Exported generic functions
serialize: Exported generic functions
serialize-json: Exported functions
skip-blanks: Internal functions

Jump to:   C   D   F   G   M   P   R   S  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   @  
S  
Index Entry  Section

@
@trivial-json-codec-contributing: Exported special variables
@trivial-json-codec-description: Exported special variables
@trivial-json-codec-example: Exported special variables
@trivial-json-codec-exported: Exported special variables
@trivial-json-codec-installing: Exported special variables
@trivial-json-codec-license: Exported special variables
@trivial-json-codec-manual: Exported special variables

S
Special Variable, @trivial-json-codec-contributing: Exported special variables
Special Variable, @trivial-json-codec-description: Exported special variables
Special Variable, @trivial-json-codec-example: Exported special variables
Special Variable, @trivial-json-codec-exported: Exported special variables
Special Variable, @trivial-json-codec-installing: Exported special variables
Special Variable, @trivial-json-codec-license: Exported special variables
Special Variable, @trivial-json-codec-manual: Exported special variables

Jump to:   @  
S  

Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   P   S   T  
Index Entry  Section

P
Package, trivial-json-codec: The trivial-json-codec package

S
System, trivial-json-codec: The trivial-json-codec system

T
trivial-json-codec: The trivial-json-codec system
trivial-json-codec: The trivial-json-codec package

Jump to:   P   S   T