Skip to content

socialmetrix/json-template-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Json Template Service

Simple HTTP docker service to render a Json template from Json data.

Templating provided by: Select Transform

Usage

Send a POST request with a json object including a data and template fields.

docker run -d -p 8080:80 socialmetrix/json-template-service

Request

{
  "data":{
    "items":[1,2,3,100,10,19]
  },
  "template":{
    "labels":{
      "{{#each items}}":{
        "type":"label",
        "text":"{{this}}"
      }
    }
  }
}

Response

{
  "labels":[
    {
      "type":"label",
      "text":1
    },
    {
      "type":"label",
      "text":2
    },
    {
      "type":"label",
      "text":3
    },
    {
      "type":"label",
      "text":100
    },
    {
      "type":"label",
      "text":10
    },
    {
      "type":"label",
      "text":19
    }
  ]
}

Template syntax

https://selecttransform.github.io/site/transform.html

Template examples

Return the content with no change
{
  "data":"Original Content",
  "template":"{{this}}"
}
Iterate over arrays
{
  "data":{
    "items":[1,2,3,100,10,19]
  },
  "template":{
    "labels":{
      "{{#each items}}":{
        "type":"label",
        "text":"{{this}}"
      }
    }
  }
}
Extract values
{
  "data":{
    "user":{
      "firstName": "Victor",
      "middleName": "Ignacio",
      "lastName": "Perez"
    }
  },
  "template":{
    "name": "{{user.firstName}} ({{user.firstName[0]}}.{{user.middleName[0]}}.{{user.lastName[0]}})."
  }
}
{"name":"Victor (V.I.P.)"}

Test

Try the library online

About

Render Json templates from Json data

Resources

License

Stars

Watchers

Forks

Packages

No packages published