Json Function
Search…
Json Function
It allows you to use methods such as where, limit, select, orderBy on JSON data.
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.
Github repository for your stars.

Usage

Install

1
$ npm install json-function
Copied!

Import

1
import JsonFunction from 'json-function';
Copied!

Usage

Example Data
1
const data = [
2
{
3
userId: 1,
4
id: 1,
5
title: "delectus aut autem",
6
completed: false
7
},
8
{
9
userId: 1,
10
id: 2,
11
title: "quis ut nam facilis et officia qui",
12
completed: false
13
},
14
{
15
userId: 1,
16
id: 3,
17
title: "fugiat veniam minus",
18
completed: false
19
},
20
{
21
userId: 1,
22
id: 4,
23
title: "et porro tempora",
24
completed: true
25
}
26
];
Copied!
Chaining Syntax
1
2
JsonFunction
3
.where({ completed: false })
4
.select(["title", "completed"])
5
.orderBy("title", "DESC")
6
.limit(2)
7
.get(data);
Copied!
Output
1
[
2
{
3
title: "quis ut nam facilis et officia qui",
4
completed: false
5
},
6
{
7
title: "fugiat veniam minus",
8
completed: false
9
}
10
];
Copied!
Basic Syntax
1
JsonFunction.where({ completed: false });
2
JsonFunction.select(["title", "completed"]);
3
JsonFunction.orderBy("title", "DESC");
4
JsonFunction.limit(2);
5
const result = JsonFunction.get(data);
Copied!

getQuery

Create a query and use it at any time.
1
const queryTwoIncompleteTasks = JsonFunction
2
.where({ completed: false })
3
.select(["title", "completed"])
4
.limit(2)
5
.getQuery();
Copied!

setQuery

1
JsonFunction.setQuery(queryTwoIncompleteTasks).get(data);
Copied!
or
1
JsonFunction.get(data, { query: queryTwoIncompleteTasks });
Copied!
Last modified 2yr ago
Copy link