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
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,14 +70,17 @@ A Node package for transforming(mapping) one JSON object to another based on a s
70
70
};
71
71
72
72
#### Template
73
-
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.
73
+
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.
74
74
75
-
**Example:** In the sample below, `id` key from input transforms to `user_id` key in output json. `content` key is not renamed since both input and output key name are same. 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.
75
+
**Update**: Starting version **0.1.4**, all keys to be included(and not to be renamed) in output json can be defined in an array named `includeTheseKeys` instead of mapping them one to one(see sample). Prior to **0.1.4**, all keys to be included in output needs to be mapped one to one.
76
+
77
+
**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.
78
+
79
+
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.
76
80
77
81
var template = {
78
82
"id" : "user_id",
79
-
"content" : "content",
80
-
"latitude" : "latitude",
83
+
"includeTheseKeys" : ["content", "latitude],
81
84
"user" : {
82
85
"desiredKey": "userDetails",
83
86
"desiredData": {
@@ -169,3 +172,4 @@ A template specifies how the input json should be transformed to the desired out
169
172
* 0.1.1 Fixed blank values in array
170
173
* 0.1.2 Bug fix for array exceeding bounds
171
174
* 0.1.3 Handling for undefined keys in JSON
175
+
* 0.1.4 Added functionality to define all keys to be included in output json, in an array instead of mapping one to one
0 commit comments