# @tmanderson/json-forms

> ### Lisp-like forms written in JSON and evaluated with JavaScript

Latest version **0.1.0** (published 2018-11-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install @tmanderson/json-forms
pnpm add @tmanderson/json-forms
yarn add @tmanderson/json-forms
bun add @tmanderson/json-forms
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2018-11-14 |
| First published | 2018-11-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 356.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Mitch Anderson |
| Maintainers | tmanderson |

## Links

- npm: https://www.npmjs.com/package/@tmanderson/json-forms
- npm.io page: https://npm.io/package/@tmanderson/json-forms

## Recent versions

- 0.1.0 (latest) — 2018-11-14

## README

# JSON Forms

### Lisp-like forms written in JSON and evaluated with JavaScript

A JavaScript interpreter for Lisp-like [forms](https://www.gnu.org/software/emacs/manual/html_node/elisp/Forms.html)
written in JSON.

### Example

```js
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](#json-forms-dsl) and the `compileAndEvaluate` method

```js
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](src/parser/grammar.pegjs)) 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](src/commands) with a `!` (eg. `$get!`) to enable debug output on
a particular query.

#### For example, this:

```
$concat
  users
    $map
      $get 'name'
```

#### Would convert to this:

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

#### As another example, this:

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

#### Would convert to:

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

---
_Source: https://npm.io/package/@tmanderson/json-forms · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
