1. Home
  2. Docs
  3. Widgelix
  4. Getting started
  5. Create Data Converter

Create Data Converter

In case when your payload a bit more complicated than a flat JSON, then you may add a data converter which translate a payload to the Widgelix.

Create your first Data Converter

Go to Data Converters on the left menu sidebar

Input Name and start to implement your JS converter in the editor
For an instance let’s define some JSON payload

  "deviceId": "00DFACE6573412", 
  "temperature": {
    "in": 28, 
    "out": 15,
    "somewhere": 296
  "pressure": {
    "space": -726, 
    "earth": 726

With the data converter we can easily translate this payload to the Widgelix

function (payload) {
  const json = JSON.parse(payload)
  let result = {}
  const topLevelKeys = Object.keys(json)
  const isObject = ({}).constructor
  for (const topLevelKey of topLevelKeys) {
    const subLevelKeys = Object.keys(json[topLevelKey])
    if (json[topLevelKey] !== isObject) {
      result[topLevelKey] = json[topLevelKey]
    for (const subLevelKey of subLevelKeys) {
      result[`${topLevelKey}-${subLevelKey}`] = json[topLevelKey][subLevelKey]
  return result

Then you can test Data Converter with sample payload

Finally, click on the Save button and you may assign the converter with a Device Type