jsonluajsontemplate

JSON Template in Lua


I have a JSON object which I would like to templatize in lua. For example:

{
  "type":"email",
  "version":"1.0",
  "account":"%emailId%"
}

I would like to substitute the %emailId% with a list of e-mail ids. Is there a templatization support for JSON in lua?


Solution

  • No, there is no built-in support for either JSON or templating in the core Lua language or libraries. There are a number of JSON modules available, but I'm not sure whether any of them have template support. You might have to write a templating function yourself, but it probably won't be too hard - it's just a matter of iterating over all the string values with the JSON module and using string.gsub on them.