
Security News
Socket Security Analysis Is Now One Click Away on npm
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.
@etclabscore/string-json-template-language
Advanced tools
A tiny language that defines a simple, familiar interface to substitute JSON into strings.
A tiny language that defines a simple, familiar interface to substitute JSON into strings.
A tiny language that defines a simple, familiar interface to substitute JSON into strings. It is derived from the template literals of Javascript, as defined in the ECMAScript Programming Language Standard, Ninth Edition ECMA-262.
The terms "object" and "array" are from the conventions of Javascript and JSON.
Specifying interfaces, runtime expression mapping, other forms of programmatically interacting with JSON and URIs.
To use the Javascript client you can:
Install it:
npm install @etclabscore/string-json-template-language --save
Import it:
import compileTemplate from "@etclabscore/string-json-template-language";
Use it somewhere:
const parsedJson = JSON.parse('{ "foo": "bar" }');
const template = "${foo}";
const resultString = compileTemplate(parsedJson, template);
// => "bar"
for the given JSON:
{
"query": {
"number": 1,
"salad": "potato"
}
}
and the given template:
http://www.example.com/foo?number=${query.number}&salad=${query.salad}
\__________/ \__________/
| |
| |
For each key in given JSON, substitute it by key into the string.
http://www.example.com/foo?number=1&salad=potato
for the given JSON
{
"query": {
"numbers": [0, 1, 2, 3],
"salads": ["caesar", "potato"]
}
}
and the given template:
http://www.example.com/foo?number=${query.numbers[1]}&salad=${query.salads[1]}
\_____________/ \_____________/
| |
| |
For each key in given JSON, subtitute it by array index into the string.
http://www.example.com/foo?number=1&salad=potato
Language Grammar defined in ABNF
grammar = *( [head] template-head identifier *["." path] *[array-left array-index array-right] template-tail [tail] )
path = *( ALPHA / "_" )
array-left = "["
array-right = "]"
array-index = *( DIGIT )
template-head = "\${"
template-tail = "}"
head = *( ALPHA / DIGIT / special-characters )
tail = *( ALPHA / DIGIT / special-characters )
identifier = *( ALPHA / "_" )
special-characters = *("-" / "_" / "~" / "." / ":" / "/" / "?" / "#" / "[" / "]" / "@" / "!" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=")
A template literal is represented within a URIs as a pair of curly braces starting with a $.
template-head = "${"
template-tail = "}"
The contents within the Template literal should be valid a key-value object mapping or array-index mapping for JSON.
grammar = *( [head] template-head identifier *["." path] *[array-left array-index array-right] template-tail [tail] )
An identifier is a valid JSON key.
identifier = *( ALPHA / "_" )
MUST be a valid nested JSON key that will be resolved with the Identifier
*["." path]
MUST be a valid index of a JSON array are represented within square brackets and MUST be a valid number.
*[array-left array-index array-right]
array-left = "["
array-right = "]"
array-index = *( DIGIT )
FAQs
A tiny language that defines a simple, familiar interface to substitute JSON into strings.
The npm package @etclabscore/string-json-template-language receives a total of 1 weekly downloads. As such, @etclabscore/string-json-template-language popularity was classified as not popular.
We found that @etclabscore/string-json-template-language demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.

Security News
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.

Product
Socket is now scanning AI agent skills across multiple languages and ecosystems, detecting malicious behavior before developers install, starting with skills.sh's 60,000+ skills.