Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
jsoncrawler
Advanced tools
Readme
jsoncrawler is a simple module that search/replace data inside complex javascript objects
Add script tag in your header
<script src="https://cdn.jsdelivr.net/npm/jsoncrawler@latest/jsoncrawler.js"></script>
Or on node.js or webpack based projects:
npm i jsoncrawler
And in your javascript:
import jsonCrawler from 'jsoncrawler';
function jsonCrawler(
object_to_search: {[key:string]: any} | any[],
value_to_search: Array<number | string | boolean>,
options: {
replace: Array<number | string | boolean>, // Value to replace. Must be in the same order as the search array.
filter: Array<number | string> // Key names or index numbers to exclude from search/replacement
}): {
path: Array<number | string>, // Nested key path in order to the parent location
key: string | number, // Key names or index number of the parent value
siblings: Array<number | string>, // Key names or index numbers of the siblings that are present on the same level
value: number | string | boolean // Value you have searched
}[]
You can scan the whole object and get the key path, key name, siblings and value
Example
let obj = {
artist: "DIA",
tracks: [
"Paradise",
{
hidden: "Come On Down"
}
]
}
let result = jsonCrawler(obj);
/*
result returns:
[
{ path: [], key: 'artist', siblings: [ 'tracks' ], value: 'DIA' },
{ path: [ 'tracks' ], key: 0, siblings: [ 1 ], value: 'Paradise' },
{
path: [ 'tracks', 1 ],
key: 'hidden',
siblings: [],
value: 'Come On Down'
}
]
*/
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'
}
]
Note: search results does not come in order.
*/
// to get to the searched data:
let ComeOnDown = obj;
result[1].path.forEach(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.forEach(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'
// Make sure the search array and replace array values are in the same order.
jsonCrawler(replace, ['Lubuntu', 'Linux'], {
replace: ['Xubuntu', 'Linus']
});
console.log(replace);
// returns ["Linus","Ubuntu",["Mint",{"mini":["Xubuntu","linux"]}]]
You can exclude your search/replacement in certain key names or index numbers
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(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 7 weekly downloads. As such, jsoncrawler popularity was classified as not popular.
We found that jsoncrawler demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.