• Stars
    star
    109
  • Rank 319,077 (Top 7 %)
  • Language
    Common Lisp
  • License
    MIT License
  • Created almost 15 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

reader/writer for the JSON format in common lisp

jsown, high performance Common Lisp json parser

jsown is a high performance Common Lisp json parser. Its aim is to allow for the fast parsing of json objects in CL. Recently, functions and macros have been added to ease the burden of writing and editing jsown objects.

jsown allows you to parse json objects quickly to a modifiable lisp list and write them back. If you only need partial retrieval of objects, jsown allows you to select the keys which you would like to see parsed. jsown also has a json writer and some helper methods to alter the json objects themselves.

parsing json objects

In order to parse a json object, simply use the parse function.

  (jsown:parse "{\"foo\":\"bar\",\"baz\":100.25}")
  =>(:OBJ ("foo" . "bar") ("baz" . 401/4))

Without any extra arguments, the parse function will return all keywords. In order to select only a few keywords, you can add those keywords in which you’re interested:

  (jsown:parse "{\"foo\":\"bar\",\"frolic\":100,\"fragrance\":10.01,\"for\":\"markup\"}" "foo" "frolic" "fragrance")
  => (:OBJ ("foo" . "bar") ("frolic" . 100) ("fragrance" . 1001/100))

In order to achieve high performance when parsing specific keywords, the keywords to be found should be known at compile time. The compiler-macro-function can calculate the keyword container with the requested keywords at compile-time. When specifying the keywords in which you’re interested you should ignore any escaped characters. For instance, supplying the string “foo” will automatically match “f\\\\oo” too."

Using jsown objects

jsown ships with some convience functions to inspect and alter the returned json content.

The fetching of the value given to a certain keyword may be done by using the val function. This function also has a setf defined on it.
The (setf val) function may alter the original object, it is however not guaranteed to do so.

  (jsown:val '(:obj ("foo" . "bar") ("frolic" . 100) ("fragrance" . 1001/100)) "frolic")
  => 100
  (setf (jsown:val '(:obj ("foo" . "bar") ("frolic" . 100) ("fragrance" . 1001/100)) "frolic") "I wasn't here before")
  => (:obj ("foo" . "bar") ("frolic" . "I wasn't here before") ("fragrance" . 1001/100))

You can build objects by using the val function too, albeit it doesn’t look really sexy.

  (setf (jsown:val (setf (jsown:val (setf (jsown:val (jsown:empty-object) "foo") "bar") "bang") (list 1 2 3 "foo" 4 5)) "bingo") 24.93)
  =>(:obj ("bingo" . 24.93) ("bang" 1 2 3 "foo" 4 5) ("foo" . "bar"))

For building objects, the macros new-js and extend-js can be used. new-js creates a new jsown object, extend-js extends an existing jsown object.

  (jsown:new-js
    ("foo" "bar")
    ("baz" (+ 100 0.25)))
  => (:obj ("baz" . 100.25) ("foo" . "bar"))

This object can be extended by use of extend-js. Say we store the previously built json object in the parameter *jsown-obj*, then we can extend it like so:

  epicdb> (jsown:extend-js *jsown-obj*
    ("bing" "bang")
    ("ping" (print "Adding ping") "pong"))
  => (:obj ("ping" . "pong") ("bing" . "bang") ("baz" . 100.25) ("foo" . "bar"))

For didactical purposes, we’ve defined ping in more than one form.

In order to see which keywords have been defined in a parsed json object, you can use the keywords function:

  (jsown:keywords '(:obj ("foo" . "bar") ("frolic" . 100) ("fragrance" . 1001/100)))
  => ("foo" "frolic" "fragrance")

You can traverse over all keywords by using the do-json-keys macro.

  CL-USER> (jsown:do-json-keys (keyword value)
               '(:obj ("foo" . "bar") ("frolic" . 100) ("fragrance" . 1001/100))
             (format T "~A => ~A~&" keyword value))
  foo => bar
  frolic => 100
  fragrance => 1001/100
  NIL

Lastly, the filter function allows you to traverse a tree of json objects and interpret its results.

  (jsown:filter (jsown:new-js
                  ("one" 100)
                  ("two" (jsown:new-js
                           ("three" (list (jsown:new-js ("four" (jsown:new-js
                                                                  ("five" "result-one"))))
                                          (jsown:new-js ("four" (jsown:new-js
                                                                  ("five" "result-two"))))
                                          (jsown:new-js ("four" (jsown:new-js
                                                                  ("five" "result-three")))))))))
                "two" "three" map "four" "five")
  => ("result-one" "result-two" "result-three")

Writing json objects

jsown supports the writing of json objects too, use the to-json CLOS method for this. You can provide an implementation for this method for your own objects so those can easily be converted to json too (and it will ensure that nested objects are correctly transformed to json).

  (jsown:to-json '(:obj ("bingo" . 24.93) ("bang" 1 2 3 "foo" 4 5) ("foo" . "bar")))
  => "{\"bingo\":24.93,\"bang\":[1,2,3,\"foo\",4,5],\"foo\":\"bar\"}"

When reading json objects, jsown converts their content to the most lispy translation of what was in there. As such json’s false will be translated to nil, which coincidentally also be the translation of json’s []. When writing objects lisp’s nil is translated to the empty json list []. You can write json’s false by writing lisp’s keywords :false or :f.

  (jsown:to-json (jsown:new-js
                   ("items" nil)
                   ("falseIsEmptyList" :f)
                   ("success" t)))
"{\"success\":true,\"falseIsEmptyList\":false,\"items\":[]}"

More Repositories

1

ember-mode

Emacs mode for navigating through emberjs projects.
Emacs Lisp
33
star
2

SEXML

extensible library for outputting XML based on DTDs and s-expressions
Common Lisp
23
star
3

org-roam-browser-extension

Org-roam extension to the browser
Emacs Lisp
21
star
4

acts_as_taggable-done-right

An acts_as_taggable plugin for rails, that puts the tags in a separate table.
Ruby
9
star
5

database-migrations

Migrations for Common Lisp
Common Lisp
9
star
6

docker-ember

Docker for ember-cli with supporting tooling
Shell
9
star
7

lisp-webservice-docker

Docker configuration for running common lisp webservices
Common Lisp
8
star
8

openid_enabled

A plugin to help authentication through OpenID
Ruby
7
star
9

cl-recaptcha

Straightforward Common Lisp recaptcha.com interconnection
Common Lisp
6
star
10

lisp-addict

Wsd17 Lisp application for WebOS
JavaScript
5
star
11

ember-public-dom-interface

Addon making it easy to offer a public dom API on components
JavaScript
5
star
12

has_barcode

A plugin for rails to easily identify objects by a barcode
Ruby
5
star
13

function-namespace

A system in which you can create separate namespaces for functions in Common Lisp. The system supports macro's and compiler-macro-functions.
Common Lisp
5
star
14

cl-fuseki

Common Lisp library for connecting to SPARQL endpoints.
Common Lisp
5
star
15

enyo-features

A library to minimize repetitive code in enyojs
JavaScript
5
star
16

books-service

Example mu-cl-resources configuration to support the JSONAPI compliant management of books and their authors.
Common Lisp
4
star
17

is-right

Common Lisp test framework which allows one to create tests from the REPL, minimizing time to write tests.
Common Lisp
4
star
18

COPP

Context Oriented Programming Patterns for ContextL
4
star
19

cl-aymore

Common Lisp Agile Yaddayadda Multipurpose Online Routable Environment
Common Lisp
4
star
20

intercom

high-level bidirectional communication channel between javascript and lisp+hunchentoot
Common Lisp
4
star
21

cl-validations

Validations for CLOS objects
Common Lisp
3
star
22

voter

mu.semte.ch application for managing votes on topics
Common Lisp
3
star
23

ember-nginx-docker

Docker configuration for hosting standalone apps built by ember-cli
3
star
24

flow

Common Lisp system to denifen flows of data/operations in your software system. This handles the (re)-direction of the data through the flow.
Common Lisp
3
star
25

versioned-objects

Allows you to create snapshots of CLOS objects
Common Lisp
3
star
26

blogworks

A rough blogging system built on top of clayworks
Common Lisp
3
star
27

clayworks

Clayworks is a full stack webdevelopment framework, consisting of a bunch of Common Lisp libraries.
Common Lisp
3
star
28

fridge

A mapping between PostgreSQL and Common Lisp objects
Common Lisp
3
star
29

lisp-substance

Companion to lisp-addict
Common Lisp
3
star
30

cl-resources-plantuml-generator

Generate UML class diagrams from your mu-cl-resources configuration
Common Lisp
2
star
31

voter-ui

Ember UI used by voter
CoffeeScript
2
star
32

cl-simple-sequence

A simple sequence utility for CL.
2
star
33

cm-openid

OpenID helpers for cl-aymore.
Common Lisp
2
star
34

plus-one-service

mu.semte.ch service for giving a +1 to a concept
Ruby
2
star
35

abcl-java-helpers

Metaprogramming support aiding in the bridge between ABCL and Java
Common Lisp
2
star
36

wiki-backend

Backend of a wiki based on mu.semte.ch
Common Lisp
2
star
37

foundyou

Common Lisp interface to the Google geocode v3 api
Common Lisp
2
star
38

mu-authorization

mu-authorization describes how and provides resources to include authorization in a custom mu-semtech project
Common Lisp
2
star
39

veeakker-webshop-backend

Backend for the veeakker webshop
Common Lisp
1
star
40

cl-css

library to aide css generation from within Common Lisp
Common Lisp
1
star
41

example-generated-app-backend

Backend of an example generated app (used for debugging)
Common Lisp
1
star
42

cl-traceable

Traceable lambda functions under SBCL
Common Lisp
1
star
43

mu-logging-local-pcap-capturing

Local pcap capturing for mu-logging-for-usernamespaces
Shell
1
star
44

cl-resources-ttl-generator

Derives ttl files from your mu-cl-resources configuration
Common Lisp
1
star
45

wiki-frontend

Frontend of a wiki based on mu.semte.ch
JavaScript
1
star
46

marawa

Multi Aspect RDFa Walker
JavaScript
1
star
47

cl-fuseki-4store-plugin

A plugin for cl-fuseki allowing it to connect through a SPARQL endpoint offered by 4store.
Common Lisp
1
star
48

cl-fuseki-blazegraph-plugin

A plugin for cl-fuseki allowing it to connect through a SPARQL endpoint offered by Blazegraph.
Common Lisp
1
star
49

root-sftp-docker

Docker instance which runs an sftp server allowing to manipulate files with root rights
Shell
1
star
50

ember-pipeline-frontend-poc

Frontend for the proof of concept pipeline specification used in big-data-europe
CoffeeScript
1
star
51

jobwallet-validator

Validator for statements based on the jobWallet certification
Common Lisp
1
star
52

mu-logging-for-user-namespaces

mu-logging which works when you using user-namespaces on Linux
Shell
1
star
53

minisearch-backend

Bcakend mu-semtech stack for a tiny search application showing how to use mu-search in authorized context
Common Lisp
1
star
54

graph-acl-basics

Repository which may serve as a starting point for working with nathanielrb/mu-graph-rewriter
Common Lisp
1
star
55

cl-fuseki-weblogic-plugin

A plugin for cl-fuseki allowing it to connect through a SPARQL endpoint offered through ABCL java code which works in weblogic.
Common Lisp
1
star