You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-7Lines changed: 9 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -8,10 +8,11 @@ A Node package for transforming(mapping) one JSON object to another based on a s
8
8
npm install json_transform --save
9
9
10
10
## Usage
11
-
11
+
```javascript
12
12
var JSONTransform =require('json_transform');
13
-
13
+
```
14
14
#### Input
15
+
```javascript
15
16
var input = {
16
17
"id":101,
17
18
"content":"My first npm package",
@@ -80,6 +81,7 @@ A Node package for transforming(mapping) one JSON object to another based on a s
80
81
]
81
82
}
82
83
};
84
+
```
83
85
84
86
#### Template
85
87
A template specifies how the input json should be transformed to the desired output json. The key value pair in template json specifies the input key to desired key name transformation(can be same if key need not be renamed). In case of nested json object/array, the desired key name is specified explicitly and the desired data specifies the template to be used for transforming inner object. The input keys not specified in the template are filtered out in the output json.
@@ -91,7 +93,7 @@ A template specifies how the input json should be transformed to the desired out
91
93
**Example:** In the sample below, `id` key from input transforms to `user_id` key in output json. `content` and `latitude` key need not be renamed so they are defined in `includeTheseKeys` array.
92
94
93
95
For the nested `user` object, the desired key is `userDetails`, so in the output, the data(specified by template `desiredData`) for `user` object comes under the key `userDetails`. The `longitude` key is not specified in template, so it is omitted from the ouput json.
94
-
96
+
```javascript
95
97
var template = {
96
98
"id":"user_id",
97
99
"includeTheseKeys": [
@@ -135,9 +137,9 @@ For the nested `user` object, the desired key is `userDetails`, so in the output
135
137
}
136
138
}
137
139
};
138
-
140
+
```
139
141
#### Output
140
-
142
+
```javascript
141
143
var output =JSONTransform.transform(input, template);
0 commit comments