0.2.2 • Published 10 years ago

json-exp v0.2.2

Weekly downloads
29
License
-
Repository
github
Last release
10 years ago

Travis

JSON Expressions

Extensible expressions for json objects based on angular expressions parser.

Install

Install using npm:

npm install json-exp

String interpolation

var result = jsonExp({
    name: "World",
    hello: "Hello ${name}"
});

result.hello; // => String: 'Hello World'

Expression evaluation

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

var scope = {
    name: 'World'
};

var result = jsonExp({
    hello: {$: '"Hello " + name'}
}, {
    scope: scope
});

result.hello; // => String: 'Hello World'

Depth

var result = JsonExp({
    user : {
        name: 'John'
    },
    userName: '$user.name'
});

result.userName; // => String: 'John'
var result = JsonExp({
    user : {
        name: 'John',
        surname: 'Smith'
        fullName: '${_.name} ${_.surname}'
    }
});

result.user.fullName; // => String: 'John Smith'
0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago