https://github.com/codefeathers/jsont
Powerful JSON templating.
https://github.com/codefeathers/jsont
Last synced: about 1 month ago
JSON representation
Powerful JSON templating.
- Host: GitHub
- URL: https://github.com/codefeathers/jsont
- Owner: codefeathers
- Created: 2018-09-06T13:16:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-21T12:53:41.000Z (over 7 years ago)
- Last Synced: 2025-08-22T02:20:47.191Z (8 months ago)
- Language: JavaScript
- Size: 102 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jsont
JSONT is an extension to JSON that lets you use templates.
JSONT's syntax extension is simple:
- anything of the format `$[var]` is replaced with the value of `var`.
- anything of the format `$[date:now]` calls the corresponding library method you supply it with.
`date` (JS Date) and `oid` (BSON ObjectID) are inbuilt library methods. The available calls are:
- `date:now`
- `data:+1h`
- `data:-1d`
- `oid:new`
- `oid:5b912a771c9d44580b1c5915`
## Usage
```JavaScript
const JSONT = require('@codefeathers/jsont');
const env = { '1': 'hello' };
console.log(
JSONT.toJSON(
JSONT.parse(
'{ "sample": "$[1]", "now": "$[date:now]" }',
env,
)));
```
Remember, the parsed template will still be a string. You have to use `.toJSON` or `JSON.parse` to parse it into an object.