Common Lisp Package: JSOWN

README:

FUNCTION

Public

BUILD-KEY-CONTAINER

Builds an internal structure to speed up the keywords which you can read. This should be used when the keywords needed are not known at compiletime, but you still want to parse those keywords of a lot of documents. If the keywords you are interested in are known at compiletime, the use of #'parse will automatically expand the kewords at compiletime. parse-with-container takes the result of this function and will return the keywords which have been inserted here.

EMPTY-OBJECT

Returns an empty object which can be used to build new objects upon

EXPORT (SYMBOLS &OPTIONAL (PACKAGE (SANE-PACKAGE)))

Exports SYMBOLS from PACKAGE, checking that no name conflicts result.

KEYWORDS (OBJECT)

Returns a list of all the keywords contained in the object

PARSE

Reads a json object from the given string, with the given keywords being the keywords which are fetched from the object. All parse functions assume <string> is not an empty json object. (string/= string "{}")

PARSE-WITH-CONTAINER

Parses the keywords which have been specified in the container from the json string json-string. For most cases you can just use the parse function without a special key container. This is only here to support some cases where the building of the key container takes too much time. See #'parse for the normal variant. See #'build-key-container for a way to build new keyword containers.

TO-JSON* (OBJECT)

Converts an object in internal jsown representation to a string containing the json representation

VAL (OBJECT KEY)

Returns the value of the given key in object

SETFVAL (VALUE OBJECT KEY)

Sets the value of the keyword key of the object object to value. If the key didn't have any value yet, the keyword is added to the object

Private

APPEND-KEY (OBJECT KEY VALUE)

Appends the given key to the object

BUFFER-INDEX (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

BUFFER-MARK (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

BUFFER-STRING (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

BUILD-BUFFER

Makes a new buffer and ensures the string is of the correct type

BUILD-CHARACTER-TREE

Builds a character tree from a set of strings

BUILD-TREE

Builds a tree from a range of lists and a function to compare its elements by

CHAR-IN-ARR

Returns t if <char> is found in <char-arr>, returns nil otherwise

CURRENT-CHAR

Returns the current character the buffer is pointing to

DECR-CHAR

Sets the pointer to the previous char in the buffer

FETCH-CHAR

Reads a character from the buffer and increases the index

ITERATE-TREE

Iterates a character-tree with the given character Returns two values, being the new tree and whether or not this is an end-point.

KEY-VAL (OBJECT KEY)

Returns the list which represents the key-val pair in the json object

MAKE-JSOWN-FILTER

Fancy filtering for jsown-parsed objects, functional implementation. look at jsown-filter for a working version.

MARK-BUFFER

Sets the mark of the buffer to the current character

MARK-LENGTH

Returns the current amount of characters in the marked piece of the buffer

NEXT-CHAR

Sets the pointer to the next char in the buffer

NEXT-CHAR/

Sets the pointer to the next char in the buffer, ignores escaped characters (they start with a \) through

NEXT-CHAR/I

Does what next-char/ does, but returns nil if no char was skipped or t if a char was skipped.

OVERWRITE-VAL (OBJECT KEY VALUE)

Overwrites the given key's value with value. Errors out if the key didn't exist

PARSE-STRING

Reads a JSON string from the stream PRE: assumes the buffer's index is at the starting " POST: returns the matching string without converting escaped characters to their internal representation POST: the buffer's index is right after the ending "

PUSH-KEY (OBJECT KEY VALUE)

Adds the given key to the object at front

READ-ARRAY

Reads a JSON array from the stream PRE: assumes the buffer's index is at the starting [ POST: returns a list containing all read objects POST: the buffer's index is right after the ending ]

READ-KEY

Reads a key from the key-value list. PRE: Assumes the buffer's index is at the starting " of the key POST: The buffer's index is right after the ending " of the key

READ-NUMBER

Reads a number from the buffer. PRE: assumes the index is pointing to the first character representing the number POST: the value of the character is returned POST: the buffer's index is at the position right after the last character representing the number

READ-OBJECT

reads an object, starting with { and ending with } into a in internal jsown object

READ-PARTIAL-KEY

reads a key from the buffer. PRE: Assumes the buffer's index is at the starting " of the key POST: Returns (values key t) if the key was found as a valid key in the tree, or (values nil nil) if it was not POST: The buffer's index is right after the ending " of the key

READ-PARTIAL-OBJECT

Reads an object from the buffer, but only when the key matches a key in the tree

READ-VALUE

Reads a value from the stream. This searches for the first meaningful character, and delegates to the right function for that character

SKIP-ARRAY

Skips the contents of an array from the buffer PRE: assumes the buffer's index is at the starting [ POST: the buffer's index is right after the ending ]

SKIP-KEY

Skips a key from the key-value list. PRE: Assumes the buffer's index is at the starting " of the key POST: The buffer's index is right after the ending " of the key

SKIP-NUMBER

Skips a number from the buffer PRE: assumes the index is pointing to the first character representing the number. POST: the buffer's index is at the position right after the last character representing the number, possibly skipping spaces after that position

SKIP-OBJECT

Skips an object from the buffer PRE: Assumes the buffer's index is at the starting { of the object POST: The buffer's index is right after the ending } of the object

SKIP-STRING

Skips the contents of an input string from the buffer. PRE: assumes the buffer's index is at the starting " POST: the buffer's index is right after the ending "

SKIP-TO

Skips characters until <char> has been found. <char> is the last char which is skipped see: skip-until

SKIP-TO/

What skip-to does, but with the ignoring of \

SKIP-UNTIL

Skips characters until <char> has been found. <char> is NOT skipped See: skip-to

SKIP-UNTIL*

Skips characters until one of the characters in <char-arr> has been found. The character which was found is not read from the buffer.

SKIP-UNTIL/

What skip-until does, but with \ escaping

SKIP-VALUE

Skips a value from the stream. This searches for the first meaningful character, and delegates to the right function for skipping that

SUBSEQ-BUFFER-MARK

Returns the content between index and mark for the current buffer result: (subseq buffer-string mark index))

SUBSEQ-TREE

Returns a sequence of the buffer, reading everything that matches with the given tree before end-char is found. end-char is not read from the buffer Returns nil if no sequence matching the tree could be found. It then stops iterating at the failed position Skips #\

SUBSEQ-UNTIL

Returns a subsequence of stream, reading everything before a character belonging to char-arr is found. The character which was found is not read from the buffer

SUBSEQ-UNTIL/

Does what subseq-until does, but does escaping too

SUBSEQ-UNTIL/UNESCAPE

Does what subseq-until/ does, but unescapes the returned string

UNESCAPE-STRING/COUNT

Unescapes the given string based on JSOWN's spec

Undocumented

SETFBUFFER-INDEX (NEW-VALUE INSTANCE)

SETFBUFFER-MARK (NEW-VALUE INSTANCE)

BUFFER-P (OBJECT)

SETFBUFFER-STRING (NEW-VALUE INSTANCE)

COPY-BUFFER (INSTANCE)

FIND-FIRST-ELTS

LIST-IS-OBJECT-P (LIST)

LIST-TO-JSON (LIST)

MAKE-BUFFER

OBJECT-TO-JSON (LIST)

PEEK-BEHIND-CHAR

TEST-READER-SPEED

WRITE-NUMBER* (OBJECT OUTPUT)

WRITE-OBJECT-TO-STREAM (OBJECT OUTPUT)

WRITE-STRING* (OBJECT OUTPUT)

MACRO

Public

DO-JSON-KEYS ((KEY VAL) OBJECT &BODY BODY)

Iterates over the json key-value pairs

EXTEND-JS (OBJ &BODY SPECS)

fills in a bunch of jsown values for obj. each spec should contain a list with the first element being the string which represents the key and the second being the form which evaluates to the value to which the key should be set. it is heavily related to jsown-object, which fills in an empty object. eg: (jsown-values (empty-object) ("kind" "onyx.Groupbox") ("components" (list (jsown-object ("content" "Hello World") ("tag" "h1")) (jsown-object ("tag" "p") ("content" "This is jsown talkin!")))))

FILTER (VALUE &REST SPECS)

Fancy filtering for jsown-parsed objects. spec can be one of the following: [object] key to find. will transform into (jsown:val value key) [cl:map] use this modifier with an [object] modifier after it, to filter all elements in the list.

NEW-JS (&BODY SPECS)

creates a new empty object and fills it is per jsown-values

Private

READ-NUMBER* (BUFFER &KEY (CURRENTLY-READING WHOLE) (EXPONENT-P T) (FLOAT-P T) (FLOAT-DELIMITERS .) (EXP-DELIMITERS eE) (NUMBER-DELIMITERS ,]} ))

This macro should be compared to inlined functions with respect to speed. The macro creates a tree of spaghetti code that can read jsown numbers to lisp numbers.

Undocumented

SET-READ-NUMBER-PART (CURRENTLY-READING BUFFER &BODY BODY)

GENERIC-FUNCTION

Public

TO-JSON (OBJECT)

Writes the given object to json in a generic way.

CLASS

Private

BUFFER

A string-buffer which is used to operate on the strings The use of a string-buffer allows us to read the data in bulk, and to operate on it, by using simple index manipulations. Reading the string up front removes the hassle of having a fixed-size maximal input

CONSTANT

Private

+COMPILE-UNESCAPE-JSON-STRINGS+

Compiles support for unescaping json strings. If you set this to nil upon compilation time strings and keywords aren't escaped. This makes the library incompliant with json, but it does make it a few % faster. Could be handy when used in a mapreduce situation where you don't mind debugging and speed is of utmost importance.