jq.js

0.0.4 • Public • Published

jq.js (A jq like, usable with Javascript)

You know jq ? You should, because it's awesomely helpful : jq.

I run into the need to use it on the browser side to easily perform JSON transformation. If this reason looks like a stupid decision, let's assume I wrote this for fun.

Status

Build Status

Installation

Yay, it's available on NPM -> npm install jq.js

It's not available on Bower, if this is problematic let me know.

Usage

const jq = require('jq.js').parse;

// This is query as we coud have written using jq
const query = '.plop.hey';

// jq parse the query and return a function performing the query
const transform = jq(query);

const obj = {
  plop: {
    hey: "Hey you !"
  }
};

// This should output "Hey you !"
console.log(transform(obj));

// > ["Hey you !"]

// OMAGAD, why an array ?

Why is the output an array ?

TL;DR : it's to allow multiple outputs and combining filters in an interesting way.

Let's see

const jq = require('jq.js').parse;

const query = '.[]';

const obj = [
  {
    plop: "aaaaaaaw"
  },
  {
    plop: "yeah"
  }
];

// This outputs :
// > [{plop: "aaaaaaaw"}, {plop: "yeah"}]
console.log(jq('.[]')(obj));

// More interesting
// This outputs
// > ["aaaaaaaw", "yeah"]
console.log(jq('.[].plop')(obj));

Features

For the moment, only reeeeally basics filters are supported, like :

  • .
  • .<key>
  • .[]

More features to come...

Readme

Keywords

none

Package Sidebar

Install

npm i jq.js

Weekly Downloads

4

Version

0.0.4

License

MIT

Last publish

Collaborators

  • thomasc__