Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

JSON Forms

Lisp-like forms written in JSON and evaluated with JavaScript

A JavaScript interpreter for Lisp-like forms written in JSON.

Example

import evaluateForm from "@tmanderson/json-forms";
// A data model
const data = { users: [{ name: "lindsay" }, { name: "tom" }] };
// A JSON Form run against the data model
const form = { $concat: { users: { $map: { $get: "name" } } } };
// The result of that form
evaluateForm(form, data); // => ['lindsay', 'tom']

Or, using JSON Forms' DSL and the compileAndEvaluate method

import { compileAndEvaluate } from "@tmandersno/json-forms";
// Our data model
const data = { users: [{ name: "lindsay" }, { name: "tom" }] };
// Our form against the model
const form = `
$concat
  users
    $map
      $get 'name'
`;
// The result of that form
compileAndEvaluate(form, data); // => ['lindsay', 'tom']

JSON Forms DSL

JSON Forms ships with a parser (grammar can be viewed here) that reduces a bit of the JSON noise when writing forms. JSON Forms exports both compileToJSON and compileAndExec methods that directly consume a JSON Form writting in the DSL.

You can append any command with a ! (eg. $get!) to enable debug output on a particular query.

For example, this:

$concat
  users
    $map
      $get 'name'

Would convert to this:

{
  $concat: {
    users: {
      $map: {
        $get: "name";
      }
    }
  }
}

As another example, this:

people
  $and!
    $has 'lastName'
    $has 'firstName'
    $concat
      'lastName'
      ','
      'firstName'

Would convert to:

{
  people: {
    $debug: true, // note: the `!` after `$and` above will debug a statement
    $and: [
      { $has: "lastName" },
      { $has: "firstName" },
      {
        $concat: ["lastName", ",", "firstName"]
      }
    ];
  }
}

About

Lisp-like forms written as JSON and evaluated with JavaScript

Topics

Resources

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.