
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
json-assign-value
Advanced tools
Assign values to JSON directly, supports direct assignments, callback and promises
browser directly!
$ npm install json-assign-value
var jsonAssignValue = require('json-assign-value')
jsonAssignValue(query, asigningValue ,options)Specify a query, what to assign and what to query. Returns a new objects with values assigned.
var data = {
people: [
{name: 'Matt', country: 'NZ'},
{name: 'Pete', country: 'AU'},
{name: 'Mikey', country: 'NZ'}
]
}
jsonAssignValue('people[country=NZ].name', 'John', {
data: data
}) //=> {people[{name: 'John', country: 'NZ'} ... etc
jsonAssignValue('people[country=NZ].name', (value) => `${value} Regan`, {
data: data, cb: true
}) //=> {people[{name: 'Matt Regan', country: 'NZ'} ... etc
jsonAssignValue('people[country=NZ].name', new Promise(resolve) => resolve("John"), {
data: data, asyncify: true
}) //=> {people[{name: 'John', country: 'NZ'} ... etc
jsonAssignValue('people[country=NZ].name', (value) => new Promise(resolve) => resolve(`${value} Regan`), {
data: data, cb: true, asyncify: true
}) //=> {people[{name: 'Matt Regan', country: 'NZ'} ... etc
data The main object to assign values.allowRegexp (optional): Enable the ~ operator. Before enabling regexp match to anyone, consider the user defined regular expression security concerns.cb Boolean, this allows users to set value as a callback function with the matched variable available in the callback.asyncify Boolean, this allows users to pass promises as the values to be setQueries are strings that describe an object or value to pluck out, or manipulate from the context object. The syntax is a little bit CSS, a little bit JS, but pretty powerful.
person.name
people[0]
people.name => return all the names of people
By default only the first matching item will be returned:
people[name=Matt]
But if you add an asterisk (*), all matching items will be returned:
people[*country=NZ]
You can use comparative operators:
people[*rating>=3]
Or use boolean logic:
people[* rating >= 3 & starred = true]
If options.enableRegexp is enabled, you can use the ~ operator to match RegExp:
people[*name~/^R/i]
You can also negate any of the above examples by adding a ! before the = or ~:
people[*country!=NZ]
MIT
FAQs
assign value to JSON based on query
We found that json-assign-value 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.