2
votes

I am trying to use a dust.js template with JSON data that has keys that contain special characters, like ":" and "#".

How can I specify these keys in my template?

For example:

JSON data:
{
    "opensearch:totalResults": 200,
    "#text": "some data"
}

dust.js template:

<div>There are {opensearch:totalResults} items found</div>

This does not resolve correctly and simply prints the template text instead of replacing with the JSON data.

1

1 Answers

5
votes

the Problem is that keys are not valid in dustjs.This is the pegjs rule that we are using to validate keys:

key "key"
 = h:[a-zA-Z_$] t:[0-9a-zA-Z_$-]*
 { return h + t.join('') }

This means that the key is valid only if:

  • Starts with a letter, underscore or $
  • The rest of the key is a letter, underscore, $ or dash (-)

As you can see the # and the : are not valid symbols to be part of the key.

If you need to add it, you can open an issue or just sent a pull request, explaining why you need this feature.