https://github.com/ekoindia/expression-utils-java
Java utility library to parse array-based nested expressions.
https://github.com/ekoindia/expression-utils-java
eko java java-utility
Last synced: 14 days ago
JSON representation
Java utility library to parse array-based nested expressions.
- Host: GitHub
- URL: https://github.com/ekoindia/expression-utils-java
- Owner: ekoindia
- Created: 2023-01-10T06:34:07.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-20T10:19:31.000Z (about 2 years ago)
- Last Synced: 2025-05-07T06:49:26.754Z (14 days ago)
- Topics: eko, java, java-utility
- Language: Java
- Homepage: https://ekoindia.github.io/expression-utils-java/
- Size: 415 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# expression-utils-java
Java utility library (with static methods) to parse array-based nested expressions.[](https://github.com/orgs/ekoindia/packages?repo_name=expression-utils-java)
[](/)
[](https://github.com/ekoindia/aeps-gateway-lib/issues)
![]()

---
## Installation
- In the [Packages](https://github.com/orgs/ekoindia/packages?repo_name=expression-utils-java) section, select the package `expression-utils-java.lib`
- Follow the installation instructions
- Or, download the library jar file and include in your Java project## Usage
- See the [Javadoc](https://ekoindia.github.io/expression-utils-java/) for detailed documentation.
- See the [test cases](lib/src/test/java/in/eko/exprutils/) for detailed usage examples.### Example
```java
import in.eko.exprutils.ExpressionParser;// Single expression example: 2 + 3
(int)ExpressionParser.parseExpression("['+', 2, 3]"); // returns 5// Nested expression example: 2 + (3 * 4)
(int)ExpressionParser.parseExpression("['+', 2, ['*', 3, 4]]"); // returns 14
```### Available functions:
| Class | Method | Inputs | Output | Desc |
|------------------|-------------------|---------------------------------------------------------|-----------------------|----------------------------------------------------------------------------------|
| [ExpressionParser](https://ekoindia.github.io/expression-utils-java/in/eko/exprutils/ExpressionParser.html) | parseExpression() | expression (string encoded Json array) | parsed value (Object) | returns parses an expression |
| | isValidOperator() | String operator | boolean | Checks if the provided operator is supported by the expressionParser |
| | interpolate() | String expr, Map data | interpolated string | Interpolate/replace values of dollar-curly-brace-wrapped variables into a string |
| [Hash](https://ekoindia.github.io/expression-utils-java/in/eko/exprutils/Hash.html) | getHash() | String input, String type | hash | Generate hash of a string using the `type` algorithm (MD5, SHA-256, etc) |
| | sha256() | String input | sha-256 hash | Generate SHA-256 hash of a string |
| | sha512() | String input | sha-512 hash | Generate SHA-512 hash of a string |
| | md5() | String input | md5 hash | Generate md5 hash of a string |
| [JsonObj](https://ekoindia.github.io/expression-utils-java/in/eko/exprutils/JsonObj.html) | get() | String/JSONObject obj, String key, String default_value | value (Object) | Retrieve deep/nested value from a JSON Object |
| | set() | String obj, String key, Object value | object (String) | Set a key-value pair deep within a JSON Object |
| [JWT](https://ekoindia.github.io/expression-utils-java/in/eko/exprutils/JWT.html) | generate() | ... | generated token | Generate JWT (token) with the given configuration |
| | parse() | ... | claim map | Validates & parses a JWT (token) |### Operators supported by the parseExpression() function:
| Operator | Purpose | Expression Example | Result |
|----------|------------------------------|----------------------------------------------------------|---------------------|
| + | Add | ['+', 2, 3] | 5 |
| - | Subtract | ['-', 3, 2] | 1 |
| * | Multiply | ['*', 2, 3] | 6 |
| / | Divide | ['/', 4, 2] | 2 |
| CONCAT | Concatenate string | ['CONCAT', 'Hello', 'World'] | HelloWorld |
| GET | Get nested-value from object | ['GET', {'b':{'d':{'e':3}}}, 'b.d.e'] | 3 |
| SET | Set nested-value into object | ['SET', {'b':{'d':{}}}, 'b.d.e', 4] | {'b':{'d':{'e':4}}} |
| SHA256 | Get sha-256 hash | ['SHA256', 'hello world'] | b94d27...cde9 |
| SHA512 | Get sha-512 hash | ['SHA512', 'hello world'] | 309ecc48...cd76f |
| MD5 | Get MD5 hash | ['MD5', 'hello world'] | 5eb63...5acdc3 |
| JWT | Generate JWT | ['JWT', '<secret-key>', 'HS256', '{"issuer":...}'] | generated token |## Contribution Guide
### Local Test
- ` ./gradlew test --info `### Local Build
- `./gradlew build`### Publish New Release
- Make sure to update the `version` number in the lib/build.gradle file
- Merge changes into the main branch
- Goto the [Releases](/releases) section and create a new release
- A new build will automatically be created and published to [Github Packages](https://github.com/orgs/ekoindia/packages?repo_name=expression-utils-java)