Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the cl-json-pointer Reference Manual, generated automatically by Declt version 4.0 beta 2 "William Riker" on Wed Jun 15 03:47:46 2022 GMT+0.
Next: Systems, Previous: The cl-json-pointer Reference Manual, Up: The cl-json-pointer Reference Manual [Contents][Index]
A JSON Pointer ( RFC6901 ) implementation for Common Lisp.
This libary aims to be independent from any JSON libraries (as much as possible).
The MIT License. See LICENSE file.
(ql:quickload "cl-json-pointer")
This library itself does not depend on any JSON libraries. You can work with your favorite one.
Current supported json libs are:
:plist
only)(asdf:load-asd "cl-json-pointer.asd")
(asdf:load-system :cl-json-pointer)
The test code depends additinal libraries:
For running tests, do below additionally.
(asdf:load-asd "cl-json-pointer-test.asd")
(asdf:test-system :cl-json-pointer)
(in-package :cl-user)
(use-package :cl-json-pointer)
(defparameter *rfc6901-example*
"{
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}")
(let ((obj (st-json:read-json-from-string *rfc6901-example*))
(cl-json-pointer:*json-object-flavor* :st-json))
(eql obj (get-by-json-pointer obj "")) ; => T
(get-by-json-pointer obj "/foo") ; => ("bar" "baz")
(get-by-json-pointer obj "/foo/0") ; => "bar"
(get-by-json-pointer obj "/") ; => 0
(get-by-json-pointer obj "/a~1b") ; => 1
(get-by-json-pointer obj "/c%d") ; => 2
(get-by-json-pointer obj "/e^f") ; => 3
(get-by-json-pointer obj "/g|h") ; => 4
(get-by-json-pointer obj "/i\\j") ; => 5
(get-by-json-pointer obj "/k\"l") ; => 6
(get-by-json-pointer obj "/ ") ; => 7
(get-by-json-pointer obj "/m~0n") ; => 8
)
;;; Uses *rfc6901-example* above.
(defparameter *obj*
(cl-json:decode-json-from-string *rfc6901-example*))
(get-by-json-pointer *obj* "/hoge" :flavor :cl-json) ; => nil
(exists-p-by-json-pointer *obj* "/hoge" :flavor :cl-json) ; => nil
;; Sets into "hoge" field.
(setf *obj*
(set-by-json-pointer *obj* "/hoge" "something" :flavor :cl-json))
(get-by-json-pointer *obj* "/hoge" :flavor :cl-json) ; => "something"
(exists-p-by-json-pointer *obj* "/hoge" :flavor :cl-json) ; => T
;; `update-by-json-pointer' is a modify macro of `set-by-json-pointer`.
(update-by-json-pointer *obj* "/hoge" "something-2" :flavor :cl-json)
(get-by-json-pointer *obj* "/hoge" :flavor :cl-json) ; => "something-2"
(exists-p-by-json-pointer *obj* "/hoge" :flavor :cl-json) ; => T
;; setf to `(get-by-json-pointer ...)' can also be used.
(setf (get-by-json-pointer *obj* "/hoge" :flavor :cl-json) "fuga")
(get-by-json-pointer *obj* "/hoge" :flavor :cl-json) ; => "fuga"
;; setting to array with index
(defparameter *obj*
(cl-json:decode-json-from-string *rfc6901-example*))
(setf *json-object-flavor* :cl-json) ; defaults :flavor to :cl-json
(get-by-json-pointer *obj* "/foo") ; => ("bar" "baz")
(update-by-json-pointer *obj* "/foo/0" "zero")
(update-by-json-pointer *obj* "/foo/1" "one")
(get-by-json-pointer *obj* "/foo") ; => ("zero" "one")
;; adding to an array tail with index
(exists-p-by-json-pointer *obj* "/foo/2") ; => NIL
(update-by-json-pointer *obj* "/foo/3" "three")
(get-by-json-pointer *obj* "/foo/3") ; => "three"
(exists-p-by-json-pointer *obj* "/foo/3") ; => T
(get-by-json-pointer *obj* "/foo/2") ; => NIL
(exists-p-by-json-pointer *obj* "/foo/2") ; => T
;; pushing to array tail with '-'
(exists-p-by-json-pointer *obj* "/foo/4") ; => NIL
(update-by-json-pointer *obj* "/foo/-" "four")
(get-by-json-pointer *obj* "/foo") ; => ("zero" "one" NIL "three" "four")
(exists-p-by-json-pointer *obj* "/foo/4") ; => T
;;; Uses *rfc6901-example* above.
(defparameter *obj*
(jsown:parse *rfc6901-example*))
(setf cl-json-pointer:*json-object-flavor* :jsown)
(get-by-json-pointer *obj* "/m~0n") ; => 8
(setf *obj*
(delete-by-json-pointer *obj* "/m~0n"))
(get-by-json-pointer *obj* "/m~0n") ; => NIL
(exists-p-by-json-pointer *obj* "/m~0n") ; => NIL
;; `deletef-by-json-pointer' is a modify macro of `delete-by-json-pointer`.
(get-by-json-pointer *obj* "/ ") ; => 7
(deletef-by-json-pointer *obj* "/ ")
(get-by-json-pointer *obj* "/ ") ; => NIL
(exists-p-by-json-pointer *obj* "/ ") ; => NIL
;;; Uses "cl-json-pointer/synonyms" system.
;;; This provides 'cljsp' package contains shorter symbols.
(asdf:load-system :cl-json-pointer/synonyms)
(defparameter *obj*
(yason:parse *rfc6901-example*))
(setf cl-json-pointer:*json-object-flavor* :yason)
(cljsp:get *obj* "/foo") ; => ("bar" "baz")
(cljsp:deletef *obj* "/foo/0")
(cljsp:get *obj* "/foo") ; => ("baz")
These symbols are exported from the cl-json-pointer
package.
Please see their docstring.
parse-json-pointer
*json-object-flavor*
get-by-json-pointer
exists-p-by-json-pointer
set-by-json-pointer
update-by-json-pointer
delete-by-json-pointer
deletef-by-json-pointer
cl-json-pointer/synonyms
Another "cl-json-pointer/synonyms" system provides "cljsp" package. This package contains some shorter symbols.
For using this, please evaluate:
(asdf:load-system :cl-json-pointer/synonyms)
After that, 'cljsp' package will be defined. It exports these symbols:
parse
get
exists-p
set
update
delete
deletef
Integration with jsown:val
functionalities.
(I think, I cound simply depend only jsown
for implementing RFC6901.)
Integration with access
library.
Next: Modules, Previous: Introduction, Up: The cl-json-pointer Reference Manual [Contents][Index]
The main system appears first, followed by any subsystem dependency.
Next: cl-json-pointer/core, Previous: Systems, Up: Systems [Contents][Index]
A JSON Pointer (RFC6901) implementation for Common Lisp.
YOKOTA Yuki <y2q.actionman@gmail.com>
MIT
Next: cl-json-pointer/st-json-support, Previous: cl-json-pointer, Up: Systems [Contents][Index]
cl-json-pointer core files.
YOKOTA Yuki <y2q.actionman@gmail.com>
MIT
src (module).
Previous: cl-json-pointer/core, Up: Systems [Contents][Index]
cl-json-pointer st-json support.
YOKOTA Yuki <y2q.actionman@gmail.com>
MIT
cl-json-pointer/core (system).
src (module).
Next: Files, Previous: Systems, Up: The cl-json-pointer Reference Manual [Contents][Index]
Modules are listed depth-first from the system components tree.
Next: cl-json-pointer/st-json-support/src, Previous: Modules, Up: Modules [Contents][Index]
cl-json-pointer/core (system).
Previous: cl-json-pointer/core/src, Up: Modules [Contents][Index]
cl-json-pointer/st-json-support (system).
support_st-json.lisp (file).
Next: Packages, Previous: Modules, Up: The cl-json-pointer Reference Manual [Contents][Index]
Files are sorted by type and then listed depth-first from the systems components trees.
Next: cl-json-pointer/core/src/package.lisp, Previous: Lisp, Up: Lisp [Contents][Index]
cl-json-pointer (system).
Next: cl-json-pointer/core/src/util.lisp, Previous: cl-json-pointer/cl-json-pointer.asd, Up: Lisp [Contents][Index]
src (module).
Next: cl-json-pointer/core/src/condition.lisp, Previous: cl-json-pointer/core/src/package.lisp, Up: Lisp [Contents][Index]
package.lisp (file).
src (module).
Next: cl-json-pointer/core/src/parser.lisp, Previous: cl-json-pointer/core/src/util.lisp, Up: Lisp [Contents][Index]
util.lisp (file).
src (module).
json-pointer-error (condition).
Next: cl-json-pointer/core/src/traversal.lisp, Previous: cl-json-pointer/core/src/condition.lisp, Up: Lisp [Contents][Index]
condition.lisp (file).
src (module).
parse-json-pointer (generic function).
Next: cl-json-pointer/core/src/interface.lisp, Previous: cl-json-pointer/core/src/parser.lisp, Up: Lisp [Contents][Index]
parser.lisp (file).
src (module).
Next: cl-json-pointer/core/src/support_library.lisp, Previous: cl-json-pointer/core/src/traversal.lisp, Up: Lisp [Contents][Index]
traversal.lisp (file).
src (module).
make-setter-by-json-pointer (function).
Next: cl-json-pointer/core/src/support_cl-json.lisp, Previous: cl-json-pointer/core/src/interface.lisp, Up: Lisp [Contents][Index]
interface.lisp (file).
src (module).
*cl-json-pointer-supported-json-flavors* (special variable).
Next: cl-json-pointer/st-json-support/src/support_st-json.lisp, Previous: cl-json-pointer/core/src/support_library.lisp, Up: Lisp [Contents][Index]
support_library.lisp (file).
src (module).
Previous: cl-json-pointer/core/src/support_cl-json.lisp, Up: Lisp [Contents][Index]
src (module).
Next: Definitions, Previous: Files, Up: The cl-json-pointer Reference Manual [Contents][Index]
Packages are listed by definition order.
Next: Indexes, Previous: Packages, Up: The cl-json-pointer Reference Manual [Contents][Index]
Definitions are sorted by export status, category, package, and then by lexicographic order.
Next: Internals, Previous: Definitions, Up: Definitions [Contents][Index]
Next: Macros, Previous: Public Interface, Up: Public Interface [Contents][Index]
Holds symbols acceptable by ‘*json-object-flavor*’ and :FLAVOR keyword argument (except ‘T’)
Default flavor of JSON library currently used.
This value is used for :FLAVOR argument of exported functions.
Currently acceptable values are held by ‘*cl-json-pointer-supported-json-flavors*’
Default is ‘t’, behaves as well as possible without any knowledge about JSON libs.
Next: Setf expanders, Previous: Special variables, Up: Public Interface [Contents][Index]
Modify macro of ‘delete-by-json-pointer’. This sets results of ‘delete-by-json-pointer’ to the referred place.
Modify macro of ‘set-by-json-pointer’. This sets results of ‘set-by-json-pointer’ to the referred place.
Next: Ordinary functions, Previous: Macros, Up: Public Interface [Contents][Index]
A setf expansion for allowing ‘setf’ to ‘(get-by-json-pointer ...)’ forms.
get-by-json-pointer (function).
Next: Generic functions, Previous: Setf expanders, Up: Public Interface [Contents][Index]
Works same as ‘set-by-json-pointer’, except this try to make a new list when setting to lists.
Traverses OBJ with POINTER, deletes the pointed place, and returns the modified OBJ
Traverses OBJ with POINTER and returns the existence of the place pointed by POINTER.
Traverses OBJ with POINTER and returns three values:
the found value (‘nil’ if not found), a generalized boolean saying the existence of the place pointed by POINTER, and NIL.
Works same as ‘delete-by-json-pointer’, except this try to make a new list when deleting from lists.
Traverses OBJ with POINTER, sets VALUE into the pointed place, and returns the modified OBJ
Next: Conditions, Previous: Ordinary functions, Up: Public Interface [Contents][Index]
Parses OBJ to an internal representation
Previous: Generic functions, Up: Public Interface [Contents][Index]
The root object of all errors related to cl-json-pointer
simple-error.
Previous: Public Interface, Up: Definitions [Contents][Index]
Next: Special variables, Previous: Internals, Up: Internals [Contents][Index]
A symbol indicates ’the (nonexistent) member after the last array element’, denoted by ’-’
Determines how to set to NIL by an index.
- ‘:list’ :: (Default) makes a new list and set <value> into nth point.
- ‘:alist’ :: pushes (reference-token . <value>) as an alist.
- ‘:plist’ :: appends (reference-token <value>) as an plist.
- ‘:error’ :: throws an error.
Determines how to set to the last (by ’-’) of NIL.
- ‘:list’ :: (Default) pushes <value> as an ordinal list.
- ‘:alist’ :: pushes (reference-token . <value>) as an alist.
- ‘:plist’ :: appends (reference-token <value>) as an plist.
- ‘:array’ :: makes a new array contains <value>.
Determines how to set to NIL by a name.
- ‘:alist’ :: (Default) pushes (reference-token . <value>) as an alist.
- ‘:plist’ :: appends (reference-token <value>) as an plist.
If this is T, cl-json-pointer trests string as atom.
Next: Ordinary functions, Previous: Special variables, Up: Internals [Contents][Index]
Used for making thunks.
Next: Generic functions, Previous: Macros, Up: Internals [Contents][Index]
Makes a fresh list whose contents is same as LIST except the car of
CONS is replaced with VALUE. If CONS is not contained in LIST,
returns a new list by appending LIST, (list VALUE) and the cdr of CONS to the LIST.
Destructively modifies LIST to exclude the CONS and successive COUNT conses. If CONS is not contained in LIST, returns a list by ‘nconc’ing LIST and (nthcdr COUNT CONS).
Makes a new adjustable fill-pointered array having same contents as ARRAY.
Destructively extends LIST to size N.
Updating functions (‘set-by-json-pointer’, ‘delete-by-json-pointer’, etc) calls this for making a setter function.
Makes a fresh list whose contents is same as LIST except the CONS and successive COUNT conses. If CONS is not contained in LIST, returns a new list by appending LIST and (nthcdr COUNT CONS).
Traverses OBJ with a parsed json-pointer (POINTER), and returns three values:
the referred object, existence (boolean), and a closure can be used as a setter.
SET-METHOD determines how to _set_ into OBJ by the returned setter:
- ‘nil’ :: No setters made. (Do not set to OBJ.)
- ‘:update’ :: Destructively updates into OBJ.
- ‘:delete’ :: Destructively deletes from OBJ.
- ‘:add’ :: If changing a list, makes a new list containing the set’ed value. (non-list objs are still modified).
- ‘:remove’ :: If deleting form a list, makes a new list not containing the removed value. (non-list objs are still modified).
FLAVOR is a keyword specifies the JSON object flavors.
See ‘*cl-json-pointer-supported-json-flavors*’
Next: Conditions, Previous: Ordinary functions, Up: Internals [Contents][Index]
Interns RTOKEN as JSON object key, with JSON lib flavor of FLAVOR
Interns RTOKEN itself as JSON object key.
This is suitable for yason, st-json, jsown, json-streams, and com.gigamonkeys.json.
Traverses OBJ with a reference token (RTOKEN), and
returns three values: a referred object, existence (boolean), and a
closure can be used as a setter.
FLAVOR is used when OBJ’s type is ambiguous, especially lists.
Indexing to an ordinal list.
Indexing to an ordinal list.
Pushing to an ordinal list.
Next: Types, Previous: Generic functions, Up: Internals [Contents][Index]
Errors at traversing an object
Initarg | Value |
---|---|
:format-control | reference token (~a) must not start with '0' when used as an index |
Errors related to the json-pointer syntax
Initarg | Value |
---|---|
:format-control | bad reference token (~a) |
(quote nil)
:reference-token
Initarg | Value |
---|---|
:format-control | reference token (~a) cannot be read as index |
Thrown by ‘parse-json-pointer’
Previous: Conditions, Up: Internals [Contents][Index]
Previous: Definitions, Up: The cl-json-pointer Reference Manual [Contents][Index]
Jump to: | (
A B C D E F G I L M P R S T U |
---|
Jump to: | (
A B C D E F G I L M P R S T U |
---|
Next: Data types, Previous: Functions, Up: Indexes [Contents][Index]
Jump to: | *
+
C R S |
---|
Jump to: | *
+
C R S |
---|
Jump to: | C F I J M P S T U |
---|
Jump to: | C F I J M P S T U |
---|