npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

lisp2json

v1.0.3

Published

Convert Lisp to JSON and back with ease!

Downloads

16

Readme

🔄 lisp2json

Convert Lisp to JSON and back with ease! 🚀

📖 Overview

lisp2json is a library and CLI tool that allows you to convert Lisp expressions to JSON and vice versa. It's perfect for developers working with Lisp who need to interface with JSON-based systems or APIs.

This project provides implementations in both Go and TypeScript.

✨ Features

  • 🔀 Convert Lisp to JSON
  • 🔁 Convert JSON to Lisp
  • 🖥️ Command-line interface
  • 📚 Reusable library
  • 🌐 Available in Go and TypeScript

🛠️ Installation

Go Version

go get github.com/tluyben/lisp2json

TypeScript Version

npm install lisp2json

🚀 Usage

As a Go library

import "github.com/tluyben/lisp2json"

// Convert Lisp to JSON
jsonStr, err := lisp2json.Lisp2JSON("(print \"Hello, World!\")")

// Convert JSON to Lisp
lispStr, err := lisp2json.JSON2Lisp("{\"cmd\":\"print\",\"args\":[{\"lit\":\"Hello, World!\",\"type\":\"string\"}]}")

As a TypeScript library

import { lisp2JSON, json2Lisp } from "lisp2json";

// Convert Lisp to JSON
const jsonStr = lisp2JSON('(print "Hello, World!")');

// Convert JSON to Lisp
const lispStr = json2Lisp(
  '{"cmd":"print","args":[{"lit":"Hello, World!","type":"string"}]}'
);

As a CLI tool (Go version)

# Convert Lisp file to JSON
./bin/lisp2json --lisp example.lsp

# Convert JSON file to Lisp
./bin/lisp2json --json example.json

As a CLI tool (TypeScript version)

# Convert Lisp file to JSON
npx lisp2json-ts --lisp example.lsp

# Convert JSON file to Lisp
npx lisp2json-ts --json example.json

🧪 Running Tests

Go Version

To run the Go tests, use the following command:

make test

TypeScript Version

To run the TypeScript tests, use the following command:

make ts-test

All Tests

To run all tests (both Go and TypeScript), use:

make all

Example run:

Building lisp2json (Go)...
Running Go tests...
Testing example1.lsp

Original:
(print "Hello, World!")

Converted to JSON:
[{"cmd":"print","args":[{"lit":"Hello, World!","type":"string"}]}]

Converted to Lisp:
(print "Hello, World!")

Testing example2.lsp

Original:
(+ (* 3 4) (- 10 5))

Converted to JSON:
[{"cmd":"+","args":[{"cmd":"*","args":[{"lit":"3","type":"number"},{"lit":"4","type":"number"}]},{"cmd":"-","args":[{"lit":"10","type":"number"},{"lit":"5","type":"number"}]}]}]

Converted to Lisp:
(+ (* 3 4) (- 10 5))

Testing example3.lsp

Original:
(if (> 5 3)
    (print "Five is greater than three")
    (print "This won't be printed"))

(if t
    (print "Five is greater than three")
    (print "This won't be printed"))

Converted to JSON:
[{"cmd":"if","args":[{"cmd":"\u003e","args":[{"lit":"5","type":"number"},{"lit":"3","type":"number"}]},{"cmd":"print","args":[{"lit":"Five is greater than three","type":"string"}]},{"cmd":"print","args":[{"lit":"This won't be printed","type":"string"}]}]},{"cmd":"if","args":[{"var":"t"},{"cmd":"print","args":[{"lit":"Five is greater than three","type":"string"}]},{"cmd":"print","args":[{"lit":"This won't be printed","type":"string"}]}]}]

Converted to Lisp:
(if (> 5 3) (print "Five is greater than three") (print "This won't be printed"))
(if t (print "Five is greater than three") (print "This won't be printed"))

Testing example4.lsp

Original:
(defun square (x)
    (* x x))
(square 5)

(defun mult2 (a b)
  (* a b))

(defun mult3 (a b c)
  (* a b c))

(print (mult2 3 4))
(print (mult3 2 3 4))

(print (mult2 5.5 2))
(print (mult3 -1 3 -2))

Converted to JSON:
[{"cmd":"defun","args":[{"var":"square"},{"args":[{"var":"x"}]},{"args":[{"cmd":"*","args":[{"var":"x"},{"var":"x"}]}]}]},{"cmd":"square","args":[{"lit":"5","type":"number"}]},{"cmd":"defun","args":[{"var":"mult2"},{"args":[{"var":"a"},{"var":"b"}]},{"args":[{"cmd":"*","args":[{"var":"a"},{"var":"b"}]}]}]},{"cmd":"defun","args":[{"var":"mult3"},{"args":[{"var":"a"},{"var":"b"},{"var":"c"}]},{"args":[{"cmd":"*","args":[{"var":"a"},{"var":"b"},{"var":"c"}]}]}]},{"cmd":"print","args":[{"cmd":"mult2","args":[{"lit":"3","type":"number"},{"lit":"4","type":"number"}]}]},{"cmd":"print","args":[{"cmd":"mult3","args":[{"lit":"2","type":"number"},{"lit":"3","type":"number"},{"lit":"4","type":"number"}]}]},{"cmd":"print","args":[{"cmd":"mult2","args":[{"lit":"5.5","type":"number"},{"lit":"2","type":"number"}]}]},{"cmd":"print","args":[{"cmd":"mult3","args":[{"lit":"-1","type":"number"},{"lit":"3","type":"number"},{"lit":"-2","type":"number"}]}]}]

Converted to Lisp:
(defun square (x) (* x x))
(square 5)
(defun mult2 (a b) (* a b))
(defun mult3 (a b c) (* a b c))
(print (mult2 3 4))
(print (mult3 2 3 4))
(print (mult2 5.5 2))
(print (mult3 -1 3 -2))

Testing example5.lsp

Original:
(cons 1 (cons 2 (cons 3 nil)))


Converted to JSON:
[{"cmd":"cons","args":[{"lit":"1","type":"number"},{"cmd":"cons","args":[{"lit":"2","type":"number"},{"cmd":"cons","args":[{"lit":"3","type":"number"},{"var":"nil"}]}]}]}]

Converted to Lisp:
(cons 1 (cons 2 (cons 3 nil)))

Testing example6.lsp

Original:
(defun factorial (n)
    (if (<= n 1)
        1
        (* n (factorial (- n 1)))))
(factorial 5)

Converted to JSON:
[{"cmd":"defun","args":[{"var":"factorial"},{"args":[{"var":"n"}]},{"args":[{"cmd":"if","args":[{"cmd":"\u003c=","args":[{"var":"n"},{"lit":"1","type":"number"}]},{"lit":"1","type":"number"},{"cmd":"*","args":[{"var":"n"},{"cmd":"factorial","args":[{"cmd":"-","args":[{"var":"n"},{"lit":"1","type":"number"}]}]}]}]}]}]},{"cmd":"factorial","args":[{"lit":"5","type":"number"}]}]

Converted to Lisp:
(defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1)))))
(factorial 5)

Testing example7.lsp

Original:
(mapcar #'(lambda (x) (* x 2)) '(1 2 3 4 5))


Converted to JSON:
[{"cmd":"mapcar","args":[{"cmd":"function","args":[{"cmd":"lambda","args":[{"cmd":"x"},{"cmd":"*","args":[{"var":"x"},{"lit":"2","type":"number"}]}]}]},{"cmd":"list","args":[{"lit":"1","type":"number"},{"lit":"2","type":"number"},{"lit":"3","type":"number"},{"lit":"4","type":"number"},{"lit":"5","type":"number"}]}]}]

Converted to Lisp:
(mapcar #'(lambda (x ) (* x 2)) '(1 2 3 4 5))

Testing example8.lsp

Original:
(let ((x 5)
      (y 3))
  (+ x y))

Converted to JSON:
[{"cmd":"let","args":[{"args":[{"args":[{"lit":"5","type":"number"}],"var":"x"},{"args":[{"lit":"3","type":"number"}],"var":"y"}]},{"cmd":"+","args":[{"var":"x"},{"var":"y"}]}]}]

Converted to Lisp:
(let ((x 5) (y 3)) (+ x y))

Testing example9.lsp

Original:
(cond ((> x 10) (print "x is greater than 10"))
      ((< x 0) (print "x is negative"))
      (t (print "x is between 0 and 10")))


Converted to JSON:
[{"cmd":"cond","args":[{"args":[{"cmd":"\u003e","args":[{"var":"x"},{"lit":"10","type":"number"}]},{"cmd":"print","args":[{"lit":"x is greater than 10","type":"string"}]}]},{"args":[{"cmd":"\u003c","args":[{"var":"x"},{"lit":"0","type":"number"}]},{"cmd":"print","args":[{"lit":"x is negative","type":"string"}]}]},{"args":[{"var":"t"},{"cmd":"print","args":[{"lit":"x is between 0 and 10","type":"string"}]}]}]}]

Converted to Lisp:
(cond ((> x 10) (print "x is greater than 10")) ((< x 0) (print "x is negative")) (t (print "x is between 0 and 10")))

Testing example10.lsp

Original:
(let ((person '((name . "Alice") (age . 30) (city . "New York"))))
  (assoc 'age person))

Converted to JSON:
[{"cmd":"let","args":[{"args":[{"args":[{"cmd":"list","args":[{"cmd":"name","args":[{"var":"."},{"lit":"Alice","type":"string"}]},{"cmd":"age","args":[{"var":"."},{"lit":"30","type":"number"}]},{"cmd":"city","args":[{"var":"."},{"lit":"New York","type":"string"}]}]}],"var":"person"}]},{"cmd":"assoc","args":[{"var":"'age"},{"var":"person"}]}]}]

Converted to Lisp:
(let ((person '((name . "Alice") (age . 30) (city . "New York")))) (assoc 'age person))

Building lisp2json (TypeScript)...
Running TypeScript tests...
Testing example1.lsp

Original:
(print "Hello, World!")

Converted to JSON:
[{"cmd":"print","args":[{"lit":"Hello, World!","type":"string"}]}]

Converted to Lisp:
(print "Hello, World!")

Testing example2.lsp

Original:
(+ (* 3 4) (- 10 5))

Converted to JSON:
[{"cmd":"+","args":[{"cmd":"*","args":[{"lit":"3","type":"number"},{"lit":"4","type":"number"}]},{"cmd":"-","args":[{"lit":"10","type":"number"},{"lit":"5","type":"number"}]}]}]

Converted to Lisp:
(+ (* 3 4) (- 10 5))

Testing example3.lsp

Original:
(if (> 5 3)
    (print "Five is greater than three")
    (print "This won't be printed"))

(if t
    (print "Five is greater than three")
    (print "This won't be printed"))

Converted to JSON:
[{"cmd":"if","args":[{"cmd":">","args":[{"lit":"5","type":"number"},{"lit":"3","type":"number"}]},{"cmd":"print","args":[{"lit":"Five is greater than three","type":"string"}]},{"cmd":"print","args":[{"lit":"This won't be printed","type":"string"}]}]},{"cmd":"if","args":[{"var":"t"},{"cmd":"print","args":[{"lit":"Five is greater than three","type":"string"}]},{"cmd":"print","args":[{"lit":"This won't be printed","type":"string"}]}]}]

Converted to Lisp:
(if (> 5 3) (print "Five is greater than three") (print "This won't be printed"))
(if t (print "Five is greater than three") (print "This won't be printed"))

Testing example4.lsp

Original:
(defun square (x)
    (* x x))
(square 5)

(defun mult2 (a b)
  (* a b))

(defun mult3 (a b c)
  (* a b c))

(print (mult2 3 4))
(print (mult3 2 3 4))

(print (mult2 5.5 2))
(print (mult3 -1 3 -2))

Converted to JSON:
[{"cmd":"defun","args":[{"var":"square"},{"args":[{"var":"x"}]},{"args":[{"cmd":"*","args":[{"var":"x"},{"var":"x"}]}]}]},{"cmd":"square","args":[{"lit":"5","type":"number"}]},{"cmd":"defun","args":[{"var":"mult2"},{"args":[{"var":"a"},{"var":"b"}]},{"args":[{"cmd":"*","args":[{"var":"a"},{"var":"b"}]}]}]},{"cmd":"defun","args":[{"var":"mult3"},{"args":[{"var":"a"},{"var":"b"},{"var":"c"}]},{"args":[{"cmd":"*","args":[{"var":"a"},{"var":"b"},{"var":"c"}]}]}]},{"cmd":"print","args":[{"cmd":"mult2","args":[{"lit":"3","type":"number"},{"lit":"4","type":"number"}]}]},{"cmd":"print","args":[{"cmd":"mult3","args":[{"lit":"2","type":"number"},{"lit":"3","type":"number"},{"lit":"4","type":"number"}]}]},{"cmd":"print","args":[{"cmd":"mult2","args":[{"lit":"5.5","type":"number"},{"lit":"2","type":"number"}]}]},{"cmd":"print","args":[{"cmd":"mult3","args":[{"lit":"-1","type":"number"},{"lit":"3","type":"number"},{"lit":"-2","type":"number"}]}]}]

Converted to Lisp:
(defun square (x) (* x x))
(square 5)
(defun mult2 (a b) (* a b))
(defun mult3 (a b c) (* a b c))
(print (mult2 3 4))
(print (mult3 2 3 4))
(print (mult2 5.5 2))
(print (mult3 -1 3 -2))

Testing example5.lsp

Original:
(cons 1 (cons 2 (cons 3 nil)))


Converted to JSON:
[{"cmd":"cons","args":[{"lit":"1","type":"number"},{"cmd":"cons","args":[{"lit":"2","type":"number"},{"cmd":"cons","args":[{"lit":"3","type":"number"},{"var":"nil"}]}]}]}]

Converted to Lisp:
(cons 1 (cons 2 (cons 3 nil)))

Testing example6.lsp

Original:
(defun factorial (n)
    (if (<= n 1)
        1
        (* n (factorial (- n 1)))))
(factorial 5)

Converted to JSON:
[{"cmd":"defun","args":[{"var":"factorial"},{"args":[{"var":"n"}]},{"args":[{"cmd":"if","args":[{"cmd":"<=","args":[{"var":"n"},{"lit":"1","type":"number"}]},{"lit":"1","type":"number"},{"cmd":"*","args":[{"var":"n"},{"cmd":"factorial","args":[{"cmd":"-","args":[{"var":"n"},{"lit":"1","type":"number"}]}]}]}]}]}]},{"cmd":"factorial","args":[{"lit":"5","type":"number"}]}]

Converted to Lisp:
(defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1)))))
(factorial 5)

Testing example7.lsp

Original:
(mapcar #'(lambda (x) (* x 2)) '(1 2 3 4 5))


Converted to JSON:
[{"cmd":"mapcar","args":[{"cmd":"function","args":[{"cmd":"lambda","args":[{"cmd":"x"},{"cmd":"*","args":[{"var":"x"},{"lit":"2","type":"number"}]}]}]},{"cmd":"list","args":[{"lit":"1","type":"number"},{"lit":"2","type":"number"},{"lit":"3","type":"number"},{"lit":"4","type":"number"},{"lit":"5","type":"number"}]}]}]

Converted to Lisp:
(mapcar #'(lambda (x ) (* x 2)) '(1 2 3 4 5))

Testing example8.lsp

Original:
(let ((x 5)
      (y 3))
  (+ x y))

Converted to JSON:
[{"cmd":"let","args":[{"args":[{"args":[{"lit":"5","type":"number"}],"var":"x"},{"args":[{"lit":"3","type":"number"}],"var":"y"}]},{"cmd":"+","args":[{"var":"x"},{"var":"y"}]}]}]

Converted to Lisp:
(let ((x 5) (y 3)) (+ x y))

Testing example9.lsp

Original:
(cond ((> x 10) (print "x is greater than 10"))
      ((< x 0) (print "x is negative"))
      (t (print "x is between 0 and 10")))


Converted to JSON:
[{"cmd":"cond","args":[{"args":[{"cmd":">","args":[{"var":"x"},{"lit":"10","type":"number"}]},{"cmd":"print","args":[{"lit":"x is greater than 10","type":"string"}]}]},{"args":[{"cmd":"<","args":[{"var":"x"},{"lit":"0","type":"number"}]},{"cmd":"print","args":[{"lit":"x is negative","type":"string"}]}]},{"args":[{"var":"t"},{"cmd":"print","args":[{"lit":"x is between 0 and 10","type":"string"}]}]}]}]

Converted to Lisp:
(cond ((> x 10) (print "x is greater than 10")) ((< x 0) (print "x is negative")) (t (print "x is between 0 and 10")))

Testing example10.lsp

Original:
(let ((person '((name . "Alice") (age . 30) (city . "New York"))))
  (assoc 'age person))

Converted to JSON:
[{"cmd":"let","args":[{"args":[{"args":[{"cmd":"list","args":[{"cmd":"name","args":[{"var":"."},{"lit":"Alice","type":"string"}]},{"cmd":"age","args":[{"var":"."},{"lit":"30","type":"number"}]},{"cmd":"city","args":[{"var":"."},{"lit":"New York","type":"string"}]}]}],"var":"person"}]},{"cmd":"assoc","args":[{"var":"'age"},{"var":"person"}]}]}]

Converted to Lisp:
(let ((person '((name . "Alice") (age . 30) (city . "New York")))) (assoc 'age person))

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

👨‍💻 Author

🌟 Show your support

Give a ⭐️ if this project helped you!