This document discusses two JavaScript libraries - where.js and select.js - for searching and transforming JSON data. Where.js allows searching JSON arrays based on values, object properties, number/string operations, and logical/conditional operations. Select.js allows selecting, renaming, and excluding object properties, and defining methods to transform objects. Various examples are provided to demonstrate the capabilities and usage of each library.
1 of 16
More Related Content
Search in JSON arrays using where and select js
1. Search in JSON Arrays
Pankaj Bhageria
Friday 23 August 13
10. select js
A JavaScript library to map and transform json
object/arrays
Friday 23 August 13
11. var input = {x:1,y:2,z:3};
var output = select(input,{rename:{x:'a',y:'b',z:'c'}}); //output is {a:1,b:
2,c:3}
Renaming Properties
Friday 23 August 13
12. var input = {x:1,y:2,z:3};
var output = select(input,{only:["y","z"]}); // output is {y:2,z:3}
var input = {x:1,y:2,z:3};
var output = select(input,{only:["y"],rename:{y:"b"} }); //output is {b:2}
Only
Friday 23 August 13
13. var input = {x:1,y:2,z:3};
var output = select(input,{except:["y"]});//output is {x:1,z:3}
var input = {x:1,y:2,z:3};
var output = select(input,{except:["y"],rename:{x:"a",z:"c"} });//output is
{b:1,c:3}
Except
Friday 23 August 13
14. var input = {x:1,y:2,z:3};
var output = select(input,{only:[],
methods:{sum:function(input){
var sum = input.x + input.y + input.z;
var avg = sum/3.0;
return {sum:sum,avg:avg}
}
}
});
//output is {sum:6,avg:2}
Methods
Friday 23 August 13
15. var input = {x:1,y:2,z:3};
var output = select(input,{only:[],
methods:{sum:function(input){
var sum = input.x + input.y + input.z;
var avg = sum/3.0;
return {sum:sum,avg:avg}
}
}
});
//output is {sum:6,avg:2}
Arrays
Friday 23 August 13