https://github.com/rumkin/json-exp
JSON Expressions library
https://github.com/rumkin/json-exp
Last synced: 11 months ago
JSON representation
JSON Expressions library
- Host: GitHub
- URL: https://github.com/rumkin/json-exp
- Owner: rumkin
- Created: 2015-07-19T17:15:44.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-09-07T23:46:32.000Z (almost 11 years ago)
- Last Synced: 2025-07-10T20:36:16.016Z (11 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/json-exp
- Size: 145 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README

# JSON Expressions
Extensible expressions for json objects based on angular expressions parser.
## Install
Install using npm:
```
npm install json-exp
```
## String interpolation
```javascript
var result = jsonExp({
name: "World",
hello: "Hello ${name}"
});
result.hello; // => String: 'Hello World'
```
## Expression evaluation
```javascript
var json = {
a: 1,
b: 2,
c: {$: 'a + b'}
};
var result = jsonExp(json);
result.c // => Number: 3
result.a = 3;
result.c // => Number: 5
```
## Scope
```javascript
var scope = {
name: 'World'
};
var result = jsonExp({
hello: {$: '"Hello " + name'}
}, {
scope: scope
});
result.hello; // => String: 'Hello World'
```
## Depth
```javascript
var result = JsonExp({
user : {
name: 'John'
},
userName: '$user.name'
});
result.userName; // => String: 'John'
```
```javascript
var result = JsonExp({
user : {
name: 'John',
surname: 'Smith'
fullName: '${_.name} ${_.surname}'
}
});
result.user.fullName; // => String: 'John Smith'
```