Documentation / Introduction

Meet Yexp

A small expression language for querying data, transforming JSON, and putting your application’s rules into words.

Yexp combines familiar JavaScript-shaped syntax with selectors and pipelines built for data. Embed it in your application or use it from the terminal.

Your first expression

Suppose you have a list of products and want the names of those under $100:

{
  "products": [
    { "name": "Keyboard", "price": 75 },
    { "name": "Monitor", "price": 350 },
    { "name": "Mouse", "price": 25 }
  ]
}

Start at the input with $, select matching products, then project their names:

$.products[.price < 100][*].name
// → ["Keyboard", "Mouse"]

Prefer JavaScript-style methods? The same query can be written as:

$.products.filter(p => p.price < 100).map(p => p.name)

Try an expression in the playground →

From expression to application

Compile your expression once and evaluate it against different inputs. Yexp executes bytecode instead of using eval() or generating JavaScript.

import { compile, evaluate } from '@cristianmartinez/yexp'

const eligible = compile('$.total >= 100 && $.member')

evaluate(eligible, { total: 150, member: true }) // true
evaluate(eligible, { total: 50, member: true })  // false

The input lives at $. Pass auxiliary data explicitly through $context and $env. See Getting started for installation, runtime usage, and CLI examples.

Choose your next step

Want to see execution in motion? Step through the VM visualizer →

Yexp documentationEdit this page ↗