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

node-red-contrib-json-extract-rules

v0.1.0

Published

Node-RED node to declaratively extract, filter, map, and aggregate JSON using JSONata and typed inputs.

Readme

node-red-contrib-json-extract-rules

JSON Extract Rules is a Node-RED custom editor/node that lets you define declarative extraction rules over a JSON source using JSONata and simple path types. Each rule performs:

select → filter → map → aggregate → output

It’s ideal for turning semi-structured JSON (e.g. parsed spreadsheets, API payloads) into clean, shaped data written back to msg, flow, or global.


Features

  • 🔎 Typed inputs with JSONata editor (“⋯”) on all relevant fields
  • 🧮 Rule pipeline: select, filter, map, aggregate
  • 🧰 Aggregators: array, set, objectByKey, first, count
  • ⚙️ Optional config file (load/save/lock/watch) under your userDir
  • 🚧 Non-blocking editor dialog so JSONata popup appears on top
  • ⚠️ NA policy: normalize ["", "NA", "N/A"] (configurable) to null
  • ✅ “On empty” and “On error” behaviors per rule

Install

npm install node-red-contrib-json-extract-rules
# or inside your Node-RED userDir:
# cd ~/.node-red
# npm i node-red-contrib-json-extract-rules

Restart Node-RED. The node appears under function as json extract.

Requires Node-RED ≥ 3.0 for the built-in JSONata editor button on typed inputs.


Quick start

  1. Drop json extract onto a flow.

  2. Set Source root (e.g. msg.data).

  3. Click Add rule and define:

    • Select scope (array to iterate) — JSONata or path
    • Filter rows — JSONata boolean
    • Mapping — build objects from each item (key/value pairs)
    • Aggregatearray, set, etc.
    • Output — where to write results (e.g. msg.extract.items)

Example (generic) to collect “active” items into msg.result.names:

  • Select: JSONata → payload.items
  • Filter: JSONata → $boolean(active)
  • Map: Key = name, Value = name
  • Aggregate: set with Value expression = name
  • Output: msg.result.names

Result:

{
  "result": {
    "names": ["alpha","bravo","charlie"]
  }
}

JSONata tips you can use here

  • Dynamic property lookup:

    $lookup(object, key)
  • Regex match (boolean via existence):

    $exists($match(text, /^ABC/i))
  • Basic transforms: $lowercase(), $replace(), $string(), $trim()

The editor’s function list is not exhaustive; you can enter functions manually.


NA policy

Normalize “empty” values to null before mapping/aggregation:

{
  "enabled": true,
  "values": ["", "NA", "N/A"]
}

Edit this in the node’s NA policy section.


Using a config file (optional)

You can store your rules in a JSON file under Node-RED’s userDir and Load / Save / Lock / Watch it from the editor.

Example file (generic):

{
  "source": { "type": "msg", "path": "data" },
  "naPolicy": { "enabled": true, "values": ["", "NA", "N/A"] },
  "rules": [
    {
      "name": "Collect active names",
      "select": "payload.items",
      "selectType": "jsonata",
      "filter": "$boolean(active)",
      "filterType": "jsonata",
      "map": [{ "key": "name", "src": "name", "srcType": "jsonata", "transform": "trim" }],
      "aggregate": { "mode": "set", "valueExpr": "name", "valueExprType": "jsonata" },
      "output": { "type": "msg", "path": "result.names" },
      "onEmpty": "ok",
      "onError": "continue"
    }
  ]
}

UI notes

  • If the JSONata editor popup (“⋯”) ever appears under your rule dialog, this node’s dialog uses non-modal mode so the JSONata editor always stacks on top.
  • Avoid custom CSS that targets .red-ui-typedInput-input — it can hide the “⋯” button.

Troubleshooting

  • “⋯ doesn’t open” Ensure the field type is set to jsonata (the pill on the left).
  • Filter never matches Test the expression in a Change node set to JSONata; confirm field names and data shape.
  • Dynamic sheet/table Use $lookup(container, key) not container[key] syntax.

Development

  • Files:

    • json-extract-rules.html — editor UI & Node-RED editor scripts
    • json-extract-rules.js — runtime (node implementation)
  • Link locally for development:

    cd ~/.node-red
    npm link /path/to/your/checkout
    node-red

License

MIT