
Company News
Jerod Santo Joins Socket as Head of Media
Allow myself to introduce... myself.
Object mapping with JSONPath qeries.
async? mapq(rules: object, source: object, context?: any): object
Map the source object using the mapping rules.
If any transformation returns a Promise, the function returns a Promise.
The rules object defines the structure of the resulting object and
contains JSONPath expressions that are applied to the
source object to obtain the corresponding value for each leaf.
import mapq from 'mapq'
const rules = { foo: { bar: '$.a.b' } }
const source = { a: { b: 'hello' } }
const result = mapq(rules, source)
console.log(result) // { foo: { bar: 'hello' } }
Rules can include transformation functions that follow the
signature (value: any, source: object, context: any) => any. The value parameter corresponds to
the value of the node being transformed. The source and context are values that were originally
passed to the map function.
Transformations are defined by using an array [string, function], where the first element is an
expression to get the value from the source, and the second is a transformation function.
function increment (value) { return value + 1 }
const rules = { foo: ['$.bar', increment] }
const source = { bar: 1 }
const result = mapq(rules, source)
console.log(result) // { foo: 2 }
If a leaf does not conform to either JSONPath expression or a transformation, then it is considered as a desired value.
const rules = {
a: 1,
b: 'hello',
c: ['foo', 'bar']
}
const source = {}
const result = mapq(rules, source)
console.log(result) // { a: 1, b: 'hello', c: ['foo', 'bar'] }
Rules may form arrays.
const rules = { foo: ['$.bar', '$.baz'] }
const source = { bar: 'hello', baz: 'world' }
const result = mapq(rules, source)
console.log(result) // { foo: ['hello', 'world'] }
Transformations are also supported for arrays.
const transform = (value) => value + 10
const rules = { foo: [['$.bar', transform], ['$.baz', transform]] }
const source = { bar: 1, baz: 2 }
const result = mapq(rules, source)
console.log(result) // { foo: [11, 12] }
FAQs
Object Mapping with JSONPath
The npm package mapq receives a total of 2 weekly downloads. As such, mapq popularity was classified as not popular.
We found that mapq 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.

Company News
Allow myself to introduce... myself.

Research
/Security News
A Twitch browser extension on Chrome and Firefox forwards users’ live OAuth session tokens through proxies controlled by a Russian bot service.

Security News
Anthropic found biased reasoning and recklessness drove Claude Mythos 5 to publish malware on PyPI and compromise a security vendor.