Gathering detailed insights and metrics for @metrichor/jmespath-plus
Gathering detailed insights and metrics for @metrichor/jmespath-plus
Gathering detailed insights and metrics for @metrichor/jmespath-plus
Gathering detailed insights and metrics for @metrichor/jmespath-plus
JMESPath with extended collection of built-in functions
npm install @metrichor/jmespath-plus
Typescript
Module System
Min. Node Version
Node Version
NPM Version
Vulnerability fixes
Updated on Jun 01, 2021
Targeting ES6
Updated on May 25, 2021
Bundling changes and package dependency updates
Updated on Feb 10, 2021
Level-up your JMESPath expressions!
Updated on Oct 17, 2020
Curated and typed lodash function extensions
Updated on Oct 16, 2020
New builtin functions and start typing lodash functions
Updated on Oct 10, 2020
TypeScript (94.85%)
JavaScript (5.15%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MPL-2.0 License
15 Stars
36 Commits
17 Watchers
7 Branches
8 Contributors
Updated on Apr 23, 2025
Latest Version
0.5.3
Package Id
@metrichor/jmespath-plus@0.5.3
Unpacked Size
657.75 kB
Size
129.25 kB
File Count
21
NPM Version
6.14.12
Node Version
12.22.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
2
26
@metrichor/jmespath-plus extends @metrichor/jmespath with lodash
functions that map well to JSON objects as well as a few extra typed functions that are native to this library.
JMESPath is a query language for JSON. It will take a JSON document as input and transform it into another JSON document given a JMESPath expression.
Where this library departs is by adding a number of extra functions to the JMESPath expressions that are helpful if you require more powerful JSON transforms of simpler expressions.
npm i @metrichor/jmespath-plus
The current JMESPath spec already describes a number of built-in functions that my be sufficient. These are already included in this library
as_lambda
- Convert strings to anonymous functions to be used as lodash predicatesas_regexp
- Convert strings to Regexp
objects to be used as lodash argumentstoJSON
- Convert JS objects to JSON stringsfromJSON
- Convert JSON strings to JS objectsmean
- Calculate the mean/average of an array of numbersmode
- Calculate the most common number in an array of numbersmedian
- Calculate the middle value from an array of numberstoFixed
- Set the precision of a floatformatNumber
- Format a number with units at a set precisionuniq
- De-duplicate a list of valuesmod
- Calculate the modulus of two numbersdivide
- Divide two numberssplit
- Split a string on a given character or character sequenceentries
- Flatten a hash into key, value tuplesformat
- Format a string given a template and input values (array/object)flatMapValue
- Flatten all values in a object into key, value tuplestoUpperCase
- Uppercase (locale based) all characters in a stringtoLowerCase
- Lowercase (locale based) all characters in a stringtrim
- Remove flanking whitespace from a stringgroupBy
- Group an array of objects by a value or expressioncombine
- Create an object from a tuple of key, value pairs (inverse of entries)Most Lodash functions that apply to JSON types are included as JMESPath function expressions and are prefixed with an _
character to ensure no name clashes and overwrites with the built-in functions.
For example the [lodash zip] function:
1/* In Javascript this looks as follows... */ 2 3_.zip(['a', 'b'], [1, 2], [true, false]); 4// => [['a', 1, true], ['b', 2, false]] 5 6 7/* In JMESPath however, this looks as follows... */ 8 9search([['a', 'b'], [1, 2], [true, false]], '_zip([0], [1], [2])') 10 11// => [['a', 1, true], ['b', 2, false]] 12
NOT ALL LODASH FUNCTIONS HAVE BEEN INCLUDED!!!!
Many lodash functions don't necessarily map to JSON objects. For a complete list of the 165 lodash
functions that are included in jmespath-plus go HERE
Many lodash functions accept function predicates as arguments. This is still possible in jmespath-plus by using a new built-in function that converts strings to functions (as_lambda
). For example:
1 2// `_findKey` JMESPath function extension 3 4const { search } = require('@metrichor/jmespath-plus'); 5 6const users = { 7 barney: { age: 36, active: true }, 8 fred: { age: 40, active: false }, 9 pebbles: { age: 1, active: true }, 10}; 11 12assert(search(users, "_findKey(@, as_lambda('o => o.age < 40'))") === 'barney'); 13
search(data: JSONValue, expression: string): JSONValue
1/* using ES modules */ 2import { search } from '@metrichor/jmespath-plus'; 3 4 5/* using CommonJS modules */ 6const search = require('@metrichor/jmespath-plus').search; 7 8 9search({foo: {bar: {baz: [0, 1, 2, 3, 4]}}}, "foo.bar.baz[2]") 10 11// OUTPUTS: 2 12
In the example we gave the search
function input data of
{foo: {bar: {baz: [0, 1, 2, 3, 4]}}}
as well as the JMESPath
expression foo.bar.baz[2]
, and the search
function evaluated
the expression against the input data to produce the result 2
.
The JMESPath language can do a lot more than select an element from a list. Here are a few more examples:
1import { search } from '@metrichor/jmespath-plus'; 2 3/* --- EXAMPLE 1 --- */ 4 5let JSON_DOCUMENT = { 6 foo: { 7 bar: { 8 baz: [0, 1, 2, 3, 4] 9 } 10 } 11}; 12 13search(JSON_DOCUMENT, "foo.bar"); 14// OUTPUTS: { baz: [ 0, 1, 2, 3, 4 ] } 15 16 17/* --- EXAMPLE 2 --- */ 18 19JSON_DOCUMENT = { 20 "foo": [ 21 {"first": "a", "last": "b"}, 22 {"first": "c", "last": "d"} 23 ] 24}; 25 26search(JSON_DOCUMENT, "foo[*].first") 27// OUTPUTS: [ 'a', 'c' ] 28 29 30/* --- EXAMPLE 3 --- */ 31 32JSON_DOCUMENT = { 33 "foo": [ 34 {"age": 20}, 35 {"age": 25}, 36 {"age": 30}, 37 {"age": 35}, 38 {"age": 40} 39 ] 40} 41 42search(JSON_DOCUMENT, "foo[?age > `30`]"); 43// OUTPUTS: [ { age: 35 }, { age: 40 } ]
registerFunction(functionName: string, customFunction: RuntimeFunction, signature: InputSignature[]): void
Extend the list of built in JMESpath expressions with your own functions.
1 import {search, registerFunction, TYPE_NUMBER} from '@metrichor/jmespath-plus' 2 3 4 search({ foo: 60, bar: 10 }, 'divide(foo, bar)') 5 // THROWS ERROR: Error: Unknown function: divide() 6 7 registerFunction( 8 'divide', // FUNCTION NAME 9 (resolvedArgs) => { // CUSTOM FUNCTION 10 const [dividend, divisor] = resolvedArgs; 11 return dividend / divisor; 12 }, 13 [{ types: [TYPE_NUMBER] }, { types: [TYPE_NUMBER] }] //SIGNATURE 14 ); 15 16 search({ foo: 60,bar: 10 }, 'divide(foo, bar)'); 17 // OUTPUTS: 6 18
compile(expression: string): ExpressionNodeTree
You can precompile all your expressions ready for use later on. the compile
function takes a JMESPath expression and returns an abstract syntax tree that
can be used by the TreeInterpreter function
1import { compile, TreeInterpreter } from '@metrichor/jmespath'; 2 3const ast = compile('foo.bar'); 4 5TreeInterpreter.search(ast, {foo: {bar: 'BAZ'}}) 6// RETURNS: "BAZ" 7
The example above only show a small amount of what a JMESPath expression can do. If you want to take a tour of the language, the best place to go is the JMESPath Tutorial.
One of the best things about JMESPath is that it is implemented in many different programming languages including python, ruby, php, lua, etc. To see a complete list of libraries, check out the JMESPath libraries page.
And finally, the full JMESPath specification can be found on the JMESPath site.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 0/26 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
22 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More