Json Function
Search…
Select
The "Select" function is a practical method where you only get the desired fields of a json data.
Github repository for your stars.

Usage

Install

1
$ npm install json-function
Copied!

Import

1
import { select } from 'json-function';
Copied!

Usage

Example Data
1
const data = [
2
{
3
firstname: "John",
4
lastname: "Doe",
5
book: {
6
id: 0,
7
title: "Book Name"
8
}
9
},
10
{
11
firstname: "Johnny",
12
lastname: "Doe",
13
book: {
14
id: 1,
15
title: "Book Name 2"
16
}
17
}
18
];
Copied!

Single Field Select Syntax

1
select(data, "firstname");
Copied!
Output
1
const data = [
2
{
3
firstname: "John",
4
},
5
{
6
firstname: "Johnny",
7
}
8
];
Copied!

Multiple Field Select Syntax

1
select(data, ["firstname", "lastname"]);
Copied!
Output
1
const data = [
2
{
3
firstname: "John",
4
lastname: "Doe",
5
},
6
{
7
firstname: "Johnny",
8
lastname: "Doe",
9
}
10
];
Copied!
Last modified 2yr ago