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 🙏

© 2024 – Pkg Stats / Ryan Hefner

insomnia-plugin-jsonata

v0.0.1

Published

Insomnia REST client plugin template tag to pull data from JSON strings using the JSONata library

Downloads

7

Readme

insomnia-plugin-jsonata

insomnia-plugin-jsonata is an Insomnia REST Client Template Tag plugin that serves as an alternative to the builtin JSONPath Template Tag

This plugin uses the community-driven JSONata NPM library to query and transform JSON data.


JSONata allows a user to have greater control over the querying and manipulation of a JSON object than the builtin JSONPath template that utilizes the JSONPath-Plus library. In many ways, JSONata is more comparable to jq than JSONPath with its extended functionality and ability to query and manipulate the object. The upside in using JSONata is that it is web native Javascript, whereas jq is written and built as a portable C single binary.

You can refer to the docs for information on writing a JSONata query filter. It's pretty straightforward:

$ as the root object

. notation for retrieving nested objects

[] filter by index or subquery

To emulate the examples that Insomnia provides regarding a hypothetical book store API:

| JSONata Query Filter | Action | |----------------------|--------| | $.store.books.title | Get titles of all books in the store | | $.store.books[price < 10].title | Get titles of books costing less than $10 | | $.store.books[-1] | Get the last book in the store | | $count($.store.books) | Get the number of books in the store | $.store.books[$match(title, /lord.*rings/)] | Get book by title regular expression

Further querying and manipulation can be done with JSONata, as is shown in these examples from a hypothetical book store:

| JSONata Query Filter | Action | |----------------------|--------| | $sum($.store.cart.products.(price * quantity)) | Calculate the total sum of the products in the shopping cart | | $.store ~> $keys() | Retrieve all of the object keys inside the store object | $.store.books.{ "title": title, "price": price } | Get all books and only return their titles and prices

Installation

This plugin may be installed as discussed in Insomnia's "Introduction to Plugins" documentation.

  1. Open Insomnia
  2. Go to Application > Preferences
  3. Go to "Plugins" tab
  4. Type "insomnia-plugin-faker" in the "Install Plugin" field
  5. Click "Install Plugin"

Usage

Add JSONata template tag

Use Template Tags (i.e., CTRL + SPACE, then find "JSONata") to add JSONata template tags.

Screenshot

Template Arguments

JSON string (string) The valid JSON string to be filtered. Must be able to be parsed by JSON.parse().

JSONata Query Filter (string) A valid JSONata query filter. Anything as simple as $ or $.data.id or even as complex as $.store.books[$match(title,/lord.*rings/)].{ "title": title, "price": price }

JSON Stringify Output (boolean) Check this if you want to explicitly pass the output from JSONata through JSON.stringify(). This is helpful in rendering objects/arrays as strings.