Skip to content
It allows you to use methods such as schema, innerJoin, where, limit, select, orderBy on JSON data.
TypeScript JavaScript
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.

Json Function

Build Status License


Lets you use where, limit, select, orderBy, and more in JSON data.


npm install json-function


yarn add json-function


JsonFunction • documentation

Json-Function provides a lot of useful functions especially for your json data. It contains the methods you need too much to eliminate unnecessary code repetition.

You can use the Json-Function methods separately, but it is possible to use them all together. You can also chain it.


import JsonFunction from "json-function";

const result = JsonFunction
  .where({ completed: false })
  .select(["title", "completed"])
  .orderBy("title", "DESC")

or Basic

import JsonFunction from "json-function";

JsonFunction.where({ completed: false });["title", "completed"]);
JsonFunction.orderBy("title", "DESC");
const result = JsonFunction.get(data);

or create a query and use it at any time.

const queryTwoIncompleteTasks = JsonFunction
  .where({ completed: false })
  .select(["title", "completed"])

Query usage

// or
JsonFunction.get(data, { query: queryTwoIncompleteTasks });


Instead of an entire "class", you can use only the methods you need.

innerJoin • documentation

The "innerJoin" function is used to join two arrays.

import { innerJoin } from "json-function";

innerJoin(data, data2, "id", "userId");

schema • documentation

The "Schema" function is a great way to reconfigure your json data and make it your own.

import { schema } from "json-function";

schema(data, {
  book: {
    id: "id",
    title: "title"
  firstname: "user.firstname",
  lastname: "user.lastname"

Use "callback" for advanced conversions.

schema(data, (sc) => ({
  id: "id",
  fullName: sc.join("user.firstname", "user.lastname")

Custom separator

schema(data, (sc) => ({
  id: "id",
  fullName: sc.join("user.firstname", "user.lastname", { separator: "_" })

Use your own special function.

schema(data, (sc) => ({
  id: "id",
  fullName: sc.custom(
    (firstname, lastname) => `${firstname.toUpperCase()} ${lastname.toUpperCase()}`,


schema(data, (sc) => ({
  id: "id",
  createdAt: sc.custom(
    (createdAt) => moment(createdAt).format("DD/MM/YYYY"),

where • documentationsamples

The "Where" function provides a comfortable method for filtering a json data.

import { where } from "json-function";

// Single
// (completed === false)
where(data, { completed: false });

// Multiple (or)
// (completed === false || userId === 2)
where(data, [{ completed: false }, { userId: 2 }]);

Use "callback" for advanced filter.

// id <= 3
where(data, (wh) => ({
  id: wh.lte(3),

Other wh methods.

wh.lte(3)        // value <= 3         // value <  3
wh.gte(3)        // value >= 3         // value >  3
wh.between(3,5)  // value >= 3 && value <= 5
wh.eq("3")       // value == 3"3")       // value != 3"test")    // value.includes("test")
wh.nin("test")   // !value.includes("test")

select • documentation

The "Select" function is a practical method where you only get the desired fields of a json data.

import { select } from "json-function";

// Single
select(data, "title");

// Multiple
select(data, ["title", "completed"]);

limit • documentation

"Limit" is used to get a limited number of elements from a json data. Almost javascript works like slice() but it is much easier and clearer.

import { limit } from "json-function";

// limit
limit(data, 2);

// limit and Start
limit(data, 2, 2);

orderBy • documentation

With the "orderBy" function you can reorder the data in your json array.

import { orderBy } from "json-function";

orderBy(data, "title", "DESC");

toArray • documentation

Converts objects into meaningful sequences.

import { toArray } from "json-function";

// default key "uid"

// custom key
toArray(data, { key: "_id_" });

transform • documentation

JSON converts the snake_case keys in your data to camelCase.

import { transform } from "json-function";

You can’t perform that action at this time.