
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
jsoncrawler
Advanced tools
jsoncrawler is a simple module that search/replace data inside complex javascript objects
Add script tag in your header
<script src="https://broadwayinc.dev/jslib/jsoncrawler/0.1.13/jsoncrawler.js"></script>
Or on node.js or webpack based projects:
npm i jsoncrawler
And in your javascript:
import {jsonCrawler} from 'jsoncrawler';
Search and locate value inside complex json object
Example
// Let's find value "DIA" and "Come On Down"
let obj = {
artist: "DIA",
tracks: [
"Paradise",
{
hidden: "Come On Down"
}
]
}
let result = jsonCrawler(obj, ["Come On Down", "DIA"]);
/*
result returns:
[
{ path: [], key: 'artist', siblings: [ 'tracks' ], value: 'DIA' },
{
// 'path' is the key path to the data location:
path: [ 'tracks', 1 ],
// 'key' is the key name of the value
key: 'hidden',
// 'siblings' is the key names that are present on the same level
siblings: [],
// 'value' is the value you have searched
value: 'Come On Down'
}
]
*/
// to get to the searched data:
let ComeOnDown = obj;
result[1].path.map(p => {
// dive in to the key path
ComeOnDown = ComeOnDown[p];
});
// your value is in the key
ComeOnDown = ComeOnDown[result[1].key];
let DIA = obj;
result[0].path.map(p => {
DIA = DIA[p];
});
DIA = DIA[result[0].key];
You can replace the value easily
Example
let replace = ['Linux', 'Ubuntu', ['Mint', {mini: ['Lubuntu', 'linux']}]];
// replace 'Lubuntu' with 'Xubuntu' and 'Linux' with 'Linus'
jsonCrawler(replace, ['Lubuntu', 'Linux'], {
replace: ['Xubuntu', 'Linus']
});
console.log(JSON.stringify(replace));
// returns ["Linus","Ubuntu",["Mint",{"mini":["Xubuntu","linux"]}]]
You can exclude your search/replacement in certain key names
Example
let replace = ['Linux', 'Ubuntu', ['Mint', {mini: ['Lubuntu', 'linux']}]];
// replace 'Lubuntu' with 'Xubuntu' and 'Linux' with 'Linus'
// but exclude data inside keyname 'mini'
jsonCrawler(replace, ['Lubuntu', 'Linux'], {
replace: ['Xubuntu', 'Linus'],
filter: ['mini']
});
console.log(JSON.stringify(replace));
// returns ["Linus","Ubuntu",["Mint",{"mini":["Lubuntu","linux"]}]]
FAQs
jsoncrawler.js lets you search complex json data
The npm package jsoncrawler receives a total of 1 weekly downloads. As such, jsoncrawler popularity was classified as not popular.
We found that jsoncrawler 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
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.