Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Promised json key search.
Use bower.
bower isntall jsonkey
<script src="./bower_components/jsonkey/dist/jsonkey_bundle.js"></script>
JSONKey
will be installed to global.
Use npm.
npm isntall jsonkey
var JSONKey = require("jsonkey");
var parser = new JSONKey(/*timeout: Number*/);
Create a json parser.
timeout
:Number :Optional(Default 100)
All promise created by key
method will be rejected when specified milliseconds was past before key was found.
var findingName = parser.key(/*key: String*/);
Create promise for value corresponding to specified key.
key
:String :Required
You can use dot notation for nested object and brackets for array index.
parser.key("name.last")
.then(function(value){
console.log("LastName is " + value);
});
parser.key("favorites[0]")
.then(function(value){
console.log("Fist favorite is " + value);
})
parser.key("address")
.then(function(value){
console.log(value);
},function(){
console.log("address is not found");
})
var jsonString = JSON.stringify({
name:{
last:"aaa",
first:"bbb"
},
age:50,
favorites:["book","beer"]
});
parser.parse(jsonString);
// "LastName is aaa"
// "Fist favorite is book"
// "address is not found"
promise
generated by key
function is chain-able.
So easily create function chain as functional programming style.
See also APIs of Promisechain.
parser.key("items")
.map(function(item){
return item.price;
})
.reduce(function(acc, price){
return acc + price;
}, 0)
.pipe(function(val){
return "TotalPrice is:" + val;
})
.then(function(result){
console.log(result);
});
var jsonString = JSON.stringify({
items:[
{name:"book", price:10},
{name:"apple", price:3},
{name:"banana", price:2},
{name:"water", price:1},
]
});
parser.parse(jsonString);
// => "TotalPrice is: 16"
JSONKey
inherits Node.js's build in EventEmitter
.
So parser works as EventEmitter
itself.
Each key in jsonString will be emitted as event.
var parser = new JSONKey();
var parser.on("age", function(age){
console.log("He is " + age + "years old");
});
var jsonString = JSON.stringify({
name:{
last:"aaa",
first:"bbb"
},
age:50,
favorites:["book","beer"]
});
parser.parse(jsonString);
Install Node.js and NPM.
git clone git://github.com/georegeosddev/jsonkey.git
cd jsonkey
npm install
npm run-script build
MIT
FAQs
Promised json key search
The npm package jsonkey receives a total of 2 weekly downloads. As such, jsonkey popularity was classified as not popular.
We found that jsonkey demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.