{"id":14263221,"url":"https://github.com/nanoporetech/jmespath-ts","last_synced_at":"2025-03-17T16:12:04.355Z","repository":{"id":40268783,"uuid":"263092459","full_name":"nanoporetech/jmespath-ts","owner":"nanoporetech","description":"Typescript translation of the jmespath.js package","archived":false,"fork":false,"pushed_at":"2023-03-16T11:34:19.000Z","size":656,"stargazers_count":67,"open_issues_count":15,"forks_count":7,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-09T14:01:49.216Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nanoporetech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-11T16:07:52.000Z","updated_at":"2025-02-17T19:50:28.000Z","dependencies_parsed_at":"2024-06-18T18:18:10.494Z","dependency_job_id":"27a3e15d-c0d3-4c62-b538-333244849a46","html_url":"https://github.com/nanoporetech/jmespath-ts","commit_stats":{"total_commits":52,"total_committers":3,"mean_commits":"17.333333333333332","dds":0.07692307692307687,"last_synced_commit":"4ee23251fee41b9d8e3b78e8a3434382755fb096"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoporetech%2Fjmespath-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoporetech%2Fjmespath-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoporetech%2Fjmespath-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoporetech%2Fjmespath-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nanoporetech","download_url":"https://codeload.github.com/nanoporetech/jmespath-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243885892,"owners_count":20363644,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-22T13:04:46.026Z","updated_at":"2025-03-17T16:12:04.332Z","avatar_url":"https://github.com/nanoporetech.png","language":"TypeScript","funding_links":[],"categories":["others"],"sub_categories":[],"readme":"![Node.js CI](https://github.com/nanoporetech/jmespath-ts/workflows/Node.js%20CI/badge.svg?branch=master)\n\n# @metrichor/jmespath\n\n\n@metrichor/jmespath is a **typescript** implementation of the [JMESPath](https://jmespath.org) spec.\n\nJMESPath is a query language for JSON. It will take a JSON document\nas input and transform it into another JSON document\ngiven a JMESPath expression.\n\n## INSTALLATION\n\n```\nnpm install @metrichor/jmespath\n```\n\n## USAGE\n\n### `search(data: JSONValue, expression: string): JSONValue`\n\n```javascript\n/* using ES modules */\nimport { search } from '@metrichor/jmespath';\n\n\n/* using CommonJS modules */\nconst search = require('@metrichor/jmespath').search;\n\n\nsearch({foo: {bar: {baz: [0, 1, 2, 3, 4]}}}, \"foo.bar.baz[2]\")\n\n// OUTPUTS: 2\n\n```\n\nIn the example we gave the `search` function input data of\n`{foo: {bar: {baz: [0, 1, 2, 3, 4]}}}` as well as the JMESPath\nexpression `foo.bar.baz[2]`, and the `search` function evaluated\nthe expression against the input data to produce the result `2`.\n\nThe JMESPath language can do *a lot* more than select an element\nfrom a list.  Here are a few more examples:\n\n```javascript\nimport { search } from '@metrichor/jmespath';\n\n/* --- EXAMPLE 1 --- */\n\nlet JSON_DOCUMENT = {\n  foo: {\n    bar: {\n      baz: [0, 1, 2, 3, 4]\n    }\n  }\n};\n\nsearch(JSON_DOCUMENT, \"foo.bar\");\n// OUTPUTS: { baz: [ 0, 1, 2, 3, 4 ] }\n\n\n/* --- EXAMPLE 2 --- */\n\nJSON_DOCUMENT = {\n  \"foo\": [\n    {\"first\": \"a\", \"last\": \"b\"},\n    {\"first\": \"c\", \"last\": \"d\"}\n  ]\n};\n\nsearch(JSON_DOCUMENT, \"foo[*].first\")\n// OUTPUTS: [ 'a', 'c' ]\n\n\n/* --- EXAMPLE 3 --- */\n\nJSON_DOCUMENT = {\n  \"foo\": [\n    {\"age\": 20},\n    {\"age\": 25},\n    {\"age\": 30},\n    {\"age\": 35},\n    {\"age\": 40}\n  ]\n}\n\nsearch(JSON_DOCUMENT, \"foo[?age \u003e `30`]\");\n// OUTPUTS: [ { age: 35 }, { age: 40 } ]\n```\n\n### `compile(expression: string): ExpressionNodeTree`\n\nYou can precompile all your expressions ready for use later on. the `compile`\nfunction takes a JMESPath expression and returns an abstract syntax tree that\ncan be used by the TreeInterpreter function\n\n```javascript\nimport { compile, TreeInterpreter } from '@metrichor/jmespath';\n\nconst ast = compile('foo.bar');\n\nTreeInterpreter.search(ast, {foo: {bar: 'BAZ'}})\n// RETURNS: \"BAZ\"\n\n```\n\n---\n## EXTENSIONS TO ORIGINAL SPEC\n\n1. ### Register you own custom functions\n\n    #### `registerFunction(functionName: string, customFunction: RuntimeFunction, signature: InputSignature[]): void`\n\n    Extend the list of built in JMESpath expressions with your own functions.\n\n    ```javascript\n      import {search, registerFunction, TYPE_NUMBER} from '@metrichor/jmespath'\n\n\n      search({ foo: 60, bar: 10 }, 'divide(foo, bar)')\n      // THROWS ERROR: Error: Unknown function: divide()\n\n      registerFunction(\n        'divide', // FUNCTION NAME\n        (resolvedArgs) =\u003e {   // CUSTOM FUNCTION\n          const [dividend, divisor] = resolvedArgs;\n          return dividend / divisor;\n        },\n        [{ types: [TYPE_NUMBER] }, { types: [TYPE_NUMBER] }] //SIGNATURE\n      );\n\n      search({ foo: 60,bar: 10 }, 'divide(foo, bar)');\n      // OUTPUTS: 6\n\n    ```\n\n    Optional arguments are supported by setting `{..., optional: true}` in argument signatures\n\n\n    ```javascript\n\n      registerFunction(\n        'divide',\n        (resolvedArgs) =\u003e {\n          const [dividend, divisor] = resolvedArgs;\n          return dividend / divisor ?? 1; //OPTIONAL DIVISOR THAT DEFAULTS TO 1\n        },\n        [{ types: [TYPE_NUMBER] }, { types: [TYPE_NUMBER], optional: true }] //SIGNATURE\n      );\n\n      search({ foo: 60, bar: 10 }, 'divide(foo)');\n      // OUTPUTS: 60\n\n    ```\n\n2. ### Root value access with `$` symbol\n\n```javascript\n\nsearch({foo: {bar: 999}, baz: [1, 2, 3]}, '$.baz[*].[@, $.foo.bar]')\n\n// OUTPUTS:\n// [ [ 1, 999 ], [ 2, 999 ], [ 3, 999 ] ]\n```\n\n\n## More Resources\n\nThe example above only show a small amount of what\na JMESPath expression can do. If you want to take a\ntour of the language, the *best* place to go is the\n[JMESPath Tutorial](http://jmespath.org/tutorial.html).\n\nOne of the best things about JMESPath is that it is\nimplemented in many different programming languages including\npython, ruby, php, lua, etc.  To see a complete list of libraries,\ncheck out the [JMESPath libraries page](http://jmespath.org/libraries.html).\n\nAnd finally, the full JMESPath specification can be found\non the [JMESPath site](http://jmespath.org/specification.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoporetech%2Fjmespath-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnanoporetech%2Fjmespath-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoporetech%2Fjmespath-ts/lists"}