Gathering detailed insights and metrics for @metrichor/jmespath
Gathering detailed insights and metrics for @metrichor/jmespath
Gathering detailed insights and metrics for @metrichor/jmespath
Gathering detailed insights and metrics for @metrichor/jmespath
Typescript translation of the jmespath.js package
npm install @metrichor/jmespath
Typescript
Module System
Min. Node Version
Node Version
NPM Version
Vulnerability fixes and community contributions
Updated on Mar 16, 2023
Vulnerability fixes
Updated on Jun 01, 2021
Security updates
Updated on May 24, 2021
Prune unused packages
Updated on Feb 10, 2021
Update dependencies to remove security vulnerabilities
Updated on Feb 10, 2021
Fix type checking for optional arguments
Updated on Oct 10, 2020
TypeScript (76.09%)
JavaScript (23.91%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MPL-2.0 License
69 Stars
55 Commits
7 Forks
17 Watchers
11 Branches
8 Contributors
Updated on Mar 26, 2025
Latest Version
0.3.1
Package Id
@metrichor/jmespath@0.3.1
Unpacked Size
397.62 kB
Size
81.78 kB
File Count
27
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
26
@metrichor/jmespath is a typescript implementation of the JMESPath spec.
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.
npm install @metrichor/jmespath
search(data: JSONValue, expression: string): JSONValue
1/* using ES modules */ 2import { search } from '@metrichor/jmespath'; 3 4 5/* using CommonJS modules */ 6const search = require('@metrichor/jmespath').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'; 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 } ]
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
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' 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
Optional arguments are supported by setting {..., optional: true}
in argument signatures
1 2 registerFunction( 3 'divide', 4 (resolvedArgs) => { 5 const [dividend, divisor] = resolvedArgs; 6 return dividend / divisor ?? 1; //OPTIONAL DIVISOR THAT DEFAULTS TO 1 7 }, 8 [{ types: [TYPE_NUMBER] }, { types: [TYPE_NUMBER], optional: true }] //SIGNATURE 9 ); 10 11 search({ foo: 60, bar: 10 }, 'divide(foo)'); 12 // OUTPUTS: 60 13
$
symbol1 2search({foo: {bar: 999}, baz: [1, 2, 3]}, '$.baz[*].[@, $.foo.bar]') 3 4// OUTPUTS: 5// [ [ 1, 999 ], [ 2, 999 ], [ 3, 999 ] ]
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 2/20 approved changesets -- score normalized to 1
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
24 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