Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Process operations on pure JSON objects.
JSONSharp.process
clones an object and processes operations returning a
modified object.
Operations are simple objects with a single property representing its name.
The operation name should be preceded by the #
(sharp) symbol to avoid
conflicts with real data.
The property value is processed by the operation logic using a given context.
Some systems need slightly different configuration between environments and contexts. This technique allows to have a good degree of reuse with a simple format.
Given the following object and context:
var config = {
'#merge': [
{debug: true, url: 'http://localhost'},
{
'#switch': {
'#property': 'env',
'#case': {
dev: {
url: 'http://dev.com/'
},
prod: {
url: 'http://prod.com/',
debug: false
}
}
}
}
]
};
var context = {
env: 'dev'
};
var devConfig = require('JSONSharp').process(config, context);
Results in the following devConfig
object:
{
debug: true, // Debug flag inherited from merging with the defaults
url: 'http://dev.com/' // Url is replaced
}
#merge
The #merge
operation takes a list of objects and deeply merges its properties
using the deepmerge library.
Examples:
JSONSharp.process({'#merge': [{a: 'a'}, {b: 'b']}, {});
// ==> {a: 'a', b: 'b'}
#switch
The #switch
operation works much like the switch Javascript statement, with the exception that it doesn't
use a break
statement.
It takes an object with the following properties:
#property
: the property name or JSONPath
to be matched for results#case
: an object mapping #property
values to desired results#case.#default
: the value will be used if no matching value is foundExamples:
var switchObj = {
'#switch': {
'#property': 'name',
'#case': {a: 'Prop A', '#default': 'not found'}
}
};
JSONSharp.process(switchObj, {});
// ==> "not found"
JSONSharp.process(switchObj, {name: 'a'});
// ==> "Prop A"
JSONSharp.process(switchObj, {name: '$.a'});
// ==> "Prop A"
A #property
starting with $.
will be resolved using the
JSONPath library, otherwise simple
property access will be used.
FAQs
Process operations on pure JSON objects
The npm package json-sharp receives a total of 0 weekly downloads. As such, json-sharp popularity was classified as not popular.
We found that json-sharp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.