{"id":22650680,"url":"https://github.com/data7expressions/jexp","last_synced_at":"2025-03-29T07:22:18.081Z","repository":{"id":57878664,"uuid":"528498044","full_name":"data7expressions/jexp","owner":"data7expressions","description":"Parser and evaluator of expressions by line of commands. The expressions correspond to the package js-expressions","archived":false,"fork":false,"pushed_at":"2024-04-08T16:08:44.000Z","size":1002,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-12T09:18:21.181Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/data7expressions.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-08-24T16:07:21.000Z","updated_at":"2024-04-14T22:34:08.124Z","dependencies_parsed_at":"2024-04-14T22:33:51.141Z","dependency_job_id":null,"html_url":"https://github.com/data7expressions/jexp","commit_stats":null,"previous_names":["expr-solver/jexp","data7expressions/jexp","flaviolionelrita/jexp"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2Fjexp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2Fjexp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2Fjexp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2Fjexp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/data7expressions","download_url":"https://codeload.github.com/data7expressions/jexp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246151571,"owners_count":20731627,"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-12-09T08:36:40.814Z","updated_at":"2025-03-29T07:22:18.040Z","avatar_url":"https://github.com/data7expressions.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JEXP\n\nCommand line application that allows parser and evaluator of json/yaml applying expressions.\n\n## Features\n\n- json and yaml formats\n- Constants, enums, number, string, datetime, variables, objects and array\n- Arithmetic , assignment , comparison , logical and bitwise operators\n- Number , string , datetime , array and nullable functions\n- Conversion functions\n- Arrow functions\n- Group functions (distinct, first, last, min, max, sum and avg)\n- Sets functions (union, intersection, difference and symmetric difference)\n- Environment variables\n\n## Global installation\n\nit is necessary to install the package globally to be able to access the command line applications.\n\n```sh\nnpm install jexp -g\n```\n\n## Usage\n\n### Commands\n\n| Command   | Description                                         |\n|-----------|-----------------------------------------------------|\n| eval      | returns the result of the expression on the source  |\n| validate  | validate the source from a schema                   |\n\n**Eval:**\n\n```sh\njexp eval \u003cexpression\u003e \u003csource\u003e [options]\n```\n\n**Validate:**\n\n```sh\njexp validate \u003cschema\u003e \u003csource\u003e [options]\n```\n\n### Expression\n\n\u003e The expressions correspond to the package [3xpr](https://www.npmjs.com/package/3xpr)\n\u003e expression that is applied to the data source  \n\u003e\n\u003e The root of the data is accessed from **dot**\n\n```sh\njexp eval '.' ./data/orders.json\n```\n\nFrom the **dot** we write the expressions\n\n```sh\njexp eval '.details.article' ./data/orders.json\n```\n\n```sh\njexp eval '.details.first(p=\u003e p.unitPrice * p.qty \u003c 3 )' ./data/orders.json\n```\n\n### Source\n\nGet data source from json file\n\n```sh\njexp eval '.[0].details' ./data/orders.json\n```\n\nGet data source from yaml file\n\n```sh\njexp eval '.min(p=\u003e p.total)' ./data/orders.yaml\n```\n\nGet data source from json stringify\n\n```sh\njexp eval 'concatenate(capitalize(.fruit.name),\" \",.fruit.color)' '{\"fruit\":{\"name\":\"apple\",\"color\":\"green\",\"price\":1.20}}'\n```\n\nGet data source from pipeline command\n\n```sh\ncurl -s https://raw.githubusercontent.com/data7expressions/jexp/main/data/orders.json | jexp eval '.number'\n```\n\n### Options\n\n| Option            | Abbreviation | Description    | Options   |\n|-------------------|--------------|----------------|-----------|\n|--output \u003cformat\u003e  |-o            |Force output    | json, yaml|\n|--beautiful        |-b            |Beautiful output|           |\n\n## Examples\n\nfile orders.js\n\n```json\n[\n  {\n    \"number\": \"20001\",\n    \"customer\": { \"firstName\": \"John\", \"lastName\": \"Murphy\" },\n    \"orderTime\": \"2022-07-30T10:15:54\",\n    \"details\": [\n      { \"article\": \"Pear\", \"unitPrice\": 1.78, \"qty\": 2 },\n      { \"article\": \"Banana\", \"unitPrice\": 1.99, \"qty\": 1 },\n      { \"article\": \"White grape\", \"unitPrice\": 2.03, \"qty\": 1 }\n    ]\n  },\n  {\n    \"number\": \"20002\",\n    \"customer\": { \"firstName\": \"Paul\", \"lastName\": \"Smith\"  },\n    \"orderTime\": \"2022-07-30T12:12:43\",\n    \"details\": [\n      { \"article\": \"Apple\", \"unitPrice\": 2.15, \"qty\": 1 },\n      { \"article\": \"Banana\", \"unitPrice\": 1.99, \"qty\": 2 },\n      { \"article\": \"Pear\", \"unitPrice\": 1.78, \"qty\": 1 }\n    ]\n  },\n  {\n    \"number\": \"20003\",\n    \"customer\": { \"firstName\": \"George\", \"lastName\": \"Williams\" },\n    \"orderTime\": \"2022-07-30T14:43:11\",\n    \"details\": [\n      { \"article\": \"Apple\", \"unitPrice\": 2.15, \"qty\": 1 },\n      { \"article\": \"Banana\", \"unitPrice\": 1.99, \"qty\": 1 },\n      { \"article\": \"Pear\", \"unitPrice\": 1.78, \"qty\": 1 },\n      { \"article\": \"White grape\", \"unitPrice\": 2.03, \"qty\": 1 }\n    ]\n  }\n]\n```\n\n**Return the entire content of the file**:\n\n```sh\njexp eval '.' ./data/orders.json\n```\n\n*Result*:\n\n```json\n[{\"number\":\"20001\",\"customer\":{\"firstName\":\"John\",\"lastName\":\"Murphy\"},\"orderTime\":\"2022-07-30T10:15:54\",\"details\":[{\"article\":\"Pear\",\"unitPrice\":1.78,\"qty\":2},{\"article\":\"Banana\",\"unitPrice\":1.99,\"qty\":1},{\"article\":\"White grape\",\"unitPrice\":2.03,\"qty\":1}]},{\"number\":\"20002\",\"customer\":{\"firstName\":\"Paul\",\"lastName\":\"Smith\"},\"orderTime\":\"2022-07-30T12:12:43\",\"details\":[{\"article\":\"Apple\",\"unitPrice\":2.15,\"qty\":1},{\"article\":\"Banana\",\"unitPrice\":1.99,\"qty\":2},{\"article\":\"Pear\",\"unitPrice\":1.78,\"qty\":1}]},{\"number\":\"20003\",\"customer\":{\"firstName\":\"George\",\"lastName\":\"Williams\"},\"orderTime\":\"2022-07-30T14:43:11\",\"details\":[{\"article\":\"Apple\",\"unitPrice\":2.15,\"qty\":1},{\"article\":\"Banana\",\"unitPrice\":1.99,\"qty\":1},{\"article\":\"Pear\",\"unitPrice\":1.78,\"qty\":1},{\"article\":\"White grape\",\"unitPrice\":2.03,\"qty\":1}]}]\n```\n\n**Returns the number property of the list**:\n\n```sh\njexp eval '.number' ./data/orders.json\n```\n\n*Result*:\n\n```json\n[\"20001\",\"20002\",\"20003\"]\n```\n\n**Concatenates two properties and capitalizes the first one**:\n\n```sh\njexp eval 'concatenate(capitalize(.fruit.name),\" \",.fruit.color)' '{\"fruit\":{\"name\":\"apple\",\"color\":\"green\",\"price\":1.20}}'\n```\n\n*Result*:\n\n```json\n\"Apple green\"\n```\n\n**Returns the first element of an array from the index in yaml format**:\n\n```sh\njexp eval '.[0]' ./data/orders.json -o yaml\n```\n\n*Result*:\n\n```yaml\nnumber: '20001'\ncustomer:\n  firstName: John\n  lastName: Murphy\norderTime: '2022-07-30T10:15:54'\ndetails:\n  - article: Pear\n    unitPrice: 1.78\n    qty: 2\n  - article: Banana\n    unitPrice: 1.99\n    qty: 1\n  - article: White grape\n    unitPrice: 2.03\n    qty: 1\n\n```\n\n**Returns the details property of the first element in beautiful format**:\n\n```sh\njexp eval '.[0].details' ./data/orders.json -b\n```\n\n*Result*:\n\n```json\n[\n  {\n    \"article\": \"Pear\",\n    \"unitPrice\": 1.78,\n    \"qty\": 2\n  },\n  {\n    \"article\": \"Banana\",\n    \"unitPrice\": 1.99,\n    \"qty\": 1\n  },\n  {\n    \"article\": \"White grape\",\n    \"unitPrice\": 2.03,\n    \"qty\": 1\n  }\n]\n```\n\n**Returns the details property of the first element, as the file is yaml, it returns it in yaml format**:\n\n```sh\njexp eval '.[0].details' ./data/orders.yaml\n```\n\n*Result*:\n\n```yaml\n- article: Pear\n  unitPrice: 1.78\n  qty: 2\n- article: Banana\n  unitPrice: 1.99\n  qty: 1\n- article: White grape\n  unitPrice: 2.03\n  qty: 1\n\n```\n\n**Returns the details property of the first element, although the file is yaml it forces the output in json format**:\n\n```sh\njexp eval '.[0].details' ./data/orders.yaml -b -o json\n```\n\n*Result*:\n\n```json\n[\n  {\n    \"article\": \"Pear\",\n    \"unitPrice\": 1.78,\n    \"qty\": 2\n  },\n  {\n    \"article\": \"Banana\",\n    \"unitPrice\": 1.99,\n    \"qty\": 1\n  },\n  {\n    \"article\": \"White grape\",\n    \"unitPrice\": 2.03,\n    \"qty\": 1\n  }\n]\n```\n\n**Returns the details property of the listing**:\n\n```sh\njexp eval '.details' ./data/orders.json\n```\n\n*Result*:\n\n```json\n[{\"article\":\"Pear\",\"unitPrice\":1.78,\"qty\":2},{\"article\":\"Banana\",\"unitPrice\":1.99,\"qty\":1},{\"article\":\"White grape\",\"unitPrice\":2.03,\"qty\":1},{\"article\":\"Apple\",\"unitPrice\":2.15,\"qty\":1},{\"article\":\"Banana\",\"unitPrice\":1.99,\"qty\":2},{\"article\":\"Pear\",\"unitPrice\":1.78,\"qty\":1},{\"article\":\"Apple\",\"unitPrice\":2.15,\"qty\":1},{\"article\":\"Banana\",\"unitPrice\":1.99,\"qty\":1},{\"article\":\"Pear\",\"unitPrice\":1.78,\"qty\":1},{\"article\":\"White grape\",\"unitPrice\":2.03,\"qty\":1}]\n```\n\n**Returns the article property of the list of details of each element of the list**:\n\n```sh\njexp eval '.details.article' ./data/orders.json\n```\n\n*Result*:\n\n```json\n[\"Pear\",\"Banana\",\"White grape\",\"Apple\",\"Banana\",\"Pear\",\"Apple\",\"Banana\",\"Pear\",\"White grape\"]\n```\n\n**The order with the smallest total**:\n\n```sh\njexp eval '.map(p=\u003e{nro:p.number,total:p.details.sum(q=\u003e q.unitPrice * q.qty)}).min(p=\u003e p.total)' ./data/orders.json\n```\n\n*Result*:\n\n```json\n7.58\n```\n\n**Get the minimum of the article property from all the details**:\n\n```sh\njexp eval '.details.min(p=\u003e p.article )' ./data/orders.json\n```\n\n*Result*:\n\n```json\n\"Apple\"\n```\n\n**Get the maximum \"unitPrice * p.qty\" from all the details**:\n\n```sh\njexp eval '.details.max(p=\u003e p.unitPrice * p.qty )' ./data/orders.json\n```\n\n*Result*:\n\n```json\n3.98\n```\n\n**Get the middle value \"unitPrice * p.qty\" from all the details**:\n\n```sh\njexp eval 'round(.details.avg(p=\u003e p.unitPrice * p.qty),2)' ./data/orders.json\n```\n\n*Result*:\n\n```json\n2.35\n```\n\n**Gets the sum of the total property**:\n\n```sh\njexp eval '.sum(p=\u003e p.total )' ./data/orders.json\n```\n\n*Result*:\n\n```json\n0\n```\n\n**Get the sum \"unitPrice * p.qty\" of the details of item 1 of the list**:\n\n```sh\njexp eval '.[1].details.sum(p=\u003e p.unitPrice * p.qty )' ./data/orders.json\n```\n\n*Result*:\n\n```json\n7.91\n```\n\n**Get the number of details where \"unitPrice * p.qty \" is less than 3**:\n\n```sh\njexp eval '.details.count(p=\u003e p.unitPrice * p.qty \u003c 3 )' ./data/orders.json\n```\n\n*Result*:\n\n```json\n8\n```\n\n**Get the first article property of all details where \"unitPrice * p.qty\" is less than 3**:\n\n```sh\njexp eval '.details.first(p=\u003e p.unitPrice * p.qty \u003c 3 ).article' ./data/orders.json\n```\n\n*Result*:\n\n```json\n\"Banana\"\n```\n\n**Get the last article property of all details where \"unitPrice * p.qty\" is less than 3**:\n\n```sh\njexp eval '.details.last(p=\u003e p.unitPrice * p.qty \u003c 3 ).article' ./data/orders.json\n```\n\n*Result*:\n\n```json\n\"White grape\"\n```\n\n**Get the first detail where \"unitPrice * p.qty\" is less than 3 in beautiful format**:\n\n```sh\njexp eval '.details.first(p=\u003e p.unitPrice * p.qty \u003c 3 )' ./data/orders.json -b\n```\n\n*Result*:\n\n```json\n{\n  \"article\": \"Banana\",\n  \"unitPrice\": 1.99,\n  \"qty\": 1\n}\n```\n\n**Get the smallest article**:\n\n```sh\njexp eval '.details.min(p=\u003e p.article )' ./data/orders.json\n```\n\n*Result*:\n\n```json\n\"Apple\"\n```\n\n**Get the total of all the details**:\n\n```sh\njexp eval '.details.max(p=\u003e p.unitPrice * p.qty )' ./data/orders.json\n```\n\n*Result*:\n\n```json\n3.98\n```\n\n**Average value of the price of the items purchased in the order 20003**:\n\n```sh\njexp eval 'round(.filter(p=\u003e p.number == \"20003\").details.avg(p=\u003e p.unitPrice),2)' ./data/orders.json\n```\n\n*Result*:\n\n```json\n2\n```\n\n**Get the total of the details of order 1**:\n\n```sh\njexp eval '.[1].details.sum(p=\u003e p.unitPrice * p.qty )' ./data/orders.json\n```\n\n*Result*:\n\n```json\n7.91\n```\n\n**Gets the number of details where the subtotal is less than 3**:\n\n```sh\njexp eval '.details.count(p=\u003e p.unitPrice * p.qty \u003c 3 )' ./data/orders.json\n```\n\n*Result*:\n\n```json\n8\n```\n\n**Get the article of the first detail where the subtotal is less than 3**:\n\n```sh\njexp eval '.details.first(p=\u003e p.unitPrice * p.qty \u003c 3 ).article' ./data/orders.json\n```\n\n*Result*:\n\n```json\n\"Banana\"\n```\n\n**Get the article of the last detail where the subtotal is less than 3**:\n\n```sh\njexp eval '.details.last(p=\u003e p.unitPrice * p.qty \u003c 3 ).article' ./data/orders.json\n```\n\n*Result*:\n\n```json\n\"White grape\"\n```\n\n**Get the first detail where the subtotal is less than 3**:\n\n```sh\njexp eval '.details.first(p=\u003e p.unitPrice * p.qty \u003c 3 )' ./data/orders.json\n```\n\n*Result*:\n\n```json\n{\"article\":\"Banana\",\"unitPrice\":1.99,\"qty\":1}\n```\n\n**Calculate the total for each order**:\n\n```sh\njexp eval '.each(p=\u003ep.total=p.details.sum(q=\u003eq.qty*q.unitPrice)).map(p=\u003e{nro:p.number,total:p.total})' ./data/orders.json\n```\n\n*Result*:\n\n```json\n[{\"nro\":\"20001\",\"total\":7.58},{\"nro\":\"20002\",\"total\":7.91},{\"nro\":\"20003\",\"total\":7.949999999999999}]\n```\n\n**Calculate the subtotal for each order**:\n\n```sh\njexp eval '.details.foreach(p=\u003ep.subtotal=p.qty*p.unitPrice).subtotal' ./data/orders.json\n```\n\n*Result*:\n\n```json\n[3.56,1.99,2.03,2.15,3.98,1.78,2.15,1.99,1.78,2.03]\n```\n\n**calculates the total of all the details**:\n\n```sh\njexp eval '.details.foreach(p=\u003etotal=nvl(total,0)+p.qty*p.unitPrice);total' ./data/orders.json\n```\n\n*Result*:\n\n```json\n23.44\n```\n\n**Get the list of items without repeating**:\n\n```sh\njexp eval '.details.distinct(p=\u003ep.article)' ./data/orders.json -b\n```\n\n*Result*:\n\n```json\n[\n  \"Pear\",\n  \"Banana\",\n  \"White grape\",\n  \"Apple\"\n]\n```\n\n**Get the total and amount of each item**:\n\n```sh\njexp eval '.details.map(p=\u003e{article:p.article,count:count(1),total:sum(p.qty * p.unitPrice)})' ./data/orders.json -b\n```\n\n*Result*:\n\n```json\n[\n  {\n    \"article\": \"Pear\",\n    \"count\": 3,\n    \"total\": 7.12\n  },\n  {\n    \"article\": \"Banana\",\n    \"count\": 3,\n    \"total\": 7.96\n  },\n  {\n    \"article\": \"White grape\",\n    \"count\": 2,\n    \"total\": 4.06\n  },\n  {\n    \"article\": \"Apple\",\n    \"count\": 2,\n    \"total\": 4.3\n  }\n]\n```\n\n**Get the total of the first order**:\n\n```sh\njexp eval '{total:.[0].details.sum(p=\u003ep.qty * p.unitPrice)}' ./data/orders.json\n```\n\n*Result*:\n\n```json\n{\"total\":7.58}\n```\n\n**Get the total of the last order**:\n\n```sh\njexp eval '{total:round(.[.length()-1].details.sum(p=\u003ep.qty * p.unitPrice),2)}' ./data/orders.json -b\n```\n\n*Result*:\n\n```json\n{\n  \"total\": 7.95\n}\n```\n\n**List the orders with their totals**:\n\n```sh\njexp eval '.map(p=\u003e{nro:p.number,total:round(p.details.sum(q=\u003eq.qty * q.unitPrice),2)})' ./data/orders.json -b\n```\n\n*Result*:\n\n```json\n[\n  {\n    \"nro\": \"20001\",\n    \"total\": 7.6\n  },\n  {\n    \"nro\": \"20002\",\n    \"total\": 7.9\n  },\n  {\n    \"nro\": \"20003\",\n    \"total\": 7.95\n  }\n]\n```\n\n**All articles that are in orders 20001 and 20003**:\n\n```sh\njexp eval '.[0].details.article.union(.[1].details.article)' ./data/orders.json\n```\n\n*Result*:\n\n```json\n[\"Pear\",\"Banana\",\"White grape\",\"Apple\"]\n```\n\n**The articles in common between order 20001 and 20002**:\n\n```sh\njexp eval '.[0].details.article.intersection(.[1].details.article)' ./data/orders.json\n```\n\n*Result*:\n\n```json\n[\"Banana\",\"Pear\"]\n```\n\n**Articles that are in order 20001 and are not in order 20002**:\n\n```sh\njexp eval '.[0].details.article.difference(.[1].details.article)' ./data/orders.json\n```\n\n*Result*:\n\n```json\n[\"White grape\"]\n```\n\n**Articles of orders 20001 and 20003 that are not shared**:\n\n```sh\njexp eval '.[0].details.article.symmetricDifference(.[1].details.article)' ./data/orders.json\n```\n\n*Result*:\n\n```json\n[\"White grape\",\"Apple\"]\n```\n\n**Get the sum \"unitPrice * p.qty\" of the details of item 1 of the list using pipeline**:\n\n```sh\ncurl -s https://raw.githubusercontent.com/data7expressions/jexp/main/data/orders.json | jexp eval '.details.sum(p=\u003e p.unitPrice * p.qty )'\n```\n\n*Result*:\n\n```json\n23.44\n```\n\n## js-expression\n\n\u003e [Js-expression](https://www.npmjs.com/package/3xpr) is an extensible expression evaluator and parser.\n\u003e\n\u003e Besides the operators, functions, variables, objects and arrays that are supported.\n\n### Documentation\n\n- [Arithmetic](https://github.com/data7expressions/3xpr/wiki/Arithmetic)\n- [Comparison](https://github.com/data7expressions/3xpr/wiki/Comparison)\n- [Logical](https://github.com/data7expressions/3xpr/wiki/Logical)\n- [Bitwise](https://github.com/data7expressions/3xpr/wiki/Bitwise)\n- [Numeric](https://github.com/data7expressions/3xpr/wiki/Numeric)\n- [String](https://github.com/data7expressions/3xpr/wiki/String)\n- [Datetime](https://github.com/data7expressions/3xpr/wiki/Datetime)\n- [Nullable](https://github.com/data7expressions/3xpr/wiki/Nullable)\n- [Conversion](https://github.com/data7expressions/3xpr/wiki/Conversion)\n- [Assignment](https://github.com/data7expressions/3xpr/wiki/Assignment)\n- [Array](https://github.com/data7expressions/3xpr/wiki/Array)\n- [Access](https://github.com/data7expressions/3xpr/wiki/Access)\n- [Arrow](https://github.com/data7expressions/3xpr/wiki/Arrow)\n- [Group](https://github.com/data7expressions/3xpr/wiki/Group)\n- [Sets](https://github.com/data7expressions/3xpr/wiki/Sets)\n- [Control flows](https://github.com/data7expressions/3xpr/wiki/Flows)\n- [Extend](https://github.com/data7expressions/3xpr/wiki/Extend)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdata7expressions%2Fjexp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdata7expressions%2Fjexp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdata7expressions%2Fjexp/lists"}