0

I need help with a JOLT Spec, I am not experienced in JOLT expression language and to get to this point to flatten the JSON response with JOLT Spec took me quite a while.

I need to add a variable that is NOT in the JSON response in my attempt I use "dev_id" : "TEST HELLO".

I am using https://jolt-demo.appspot.com/#inception to test the JOLT Spec where I add dev_id" : "TEST HELLO" but I cannot find dev_id in the output and no errors on syntax.

Thanks in advance.

My JSON response looks like this:

{
  "id": 25692584,
  "timestamp": "2018-11-19T07:23:07.022916",
  "notification": "$device-add",
  "parameters": {
    "id": "aa190000-3143-0000-2020",
    "isBlocked": false,
    "name": "aa190000-3143-0000-2020",
    "status": "Online",
    "type": "DOOR",
    "time": "2000-01-01T02:00:39.000000",
    "secure": true,
    "mode": "idle",
    "gps.lat": 24.675699,
    "gps.long": 46.663898,
    "entries": "959,reboot 0x0001",
    "data": {
      "desc": "Undescribed",
      "imei": "861107036",
      "simid": "89564700000"
    },
    "network": {
      "id": 11,
      "name": "TEST",
      "description": null
    },
    "deviceClass": {
      "id": 12,
      "name": "CGM_IOT",
      "version": "2.0",
      "isPermanent": false,
      "offlineTimeout": 60,
      "data": null,
      "equipment": []
    }
  }
}

I then use the following JOLT Spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "parameters": {
        "*": "parameters-&",
        "data": {
          "*": "data-&"
        },
        "network": {
          "*": "network-&"
        },
        "deviceClass": {
          "*": "deviceClass-&"
        }
      }
    }
    }
]

And receive the following output:

{
  "id" : 25692584,
  "timestamp" : "2018-11-19T07:23:07.022916",
  "notification" : "$device-add",
  "parameters-id" : "aa190000-3143-0000-2020",
  "parameters-isBlocked" : false,
  "parameters-name" : "aa190000-3143-0000-2020",
  "parameters-status" : "Online",
  "parameters-type" : "DOOR",
  "parameters-time" : "2000-01-01T02:00:39.000000",
  "parameters-secure" : true,
  "parameters-mode" : "idle",
  "parameters-gps.lat" : 24.675699,
  "parameters-gps.long" : 46.663898,
  "parameters-entries" : "959,reboot 0x0001",
  "data-desc" : "Undescribed",
  "data-imei" : "861107036",
  "data-simid" : "89564700000",
  "network-id" : 11,
  "network-name" : "TEST",
  "network-description" : null,
  "deviceClass-id" : 12,
  "deviceClass-name" : "CGM_IOT",
  "deviceClass-version" : "2.0",
  "deviceClass-isPermanent" : false,
  "deviceClass-offlineTimeout" : 60,
  "deviceClass-data" : null,
  "deviceClass-equipment" : [ ]
}    

What I have tried in the JOLT Spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "dev_id": "TEST HELLO",
      "parameters": {
        "*": "parameters-&",
        "data": {
          "*": "data-&"
        },
        "network": {
          "*": "network-&"
        },
        "deviceClass": {
          "*": "deviceClass-&"
        }
      }
    }
    }
]

My expected output:

{
  "id" : 25692584,
  "timestamp" : "2018-11-19T07:23:07.022916",
  "notification" : "$device-add",
  "dev_id" : "TEST HELLO",
  "parameters-id" : "aa190000-3143-0000-2020",
  "parameters-isBlocked" : false,
  "parameters-name" : "aa190000-3143-0000-2020",
  "parameters-status" : "Online",
  "parameters-type" : "DOOR",
  "parameters-time" : "2000-01-01T02:00:39.000000",
  "parameters-secure" : true,
  "parameters-mode" : "idle",
  "parameters-gps.lat" : 24.675699,
  "parameters-gps.long" : 46.663898,
  "parameters-entries" : "959,reboot 0x0001",
  "data-desc" : "Undescribed",
  "data-imei" : "861107036",
  "data-simid" : "89564700000",
  "network-id" : 11,
  "network-name" : "TEST",
  "network-description" : null,
  "deviceClass-id" : 12,
  "deviceClass-name" : "CGM_IOT",
  "deviceClass-version" : "2.0",
  "deviceClass-isPermanent" : false,
  "deviceClass-offlineTimeout" : 60,
  "deviceClass-data" : null,
  "deviceClass-equipment" : [ ]
} 

1 Answers1

0

During shift "values are the keys" and "keys are the values" you can use # to set the value as a constant:

[
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "#TEST HELLO": "dev_id",
      "parameters": {
        "*": "parameters-&",
        "data": {
          "*": "data-&"
        },
        "network": {
          "*": "network-&"
        },
        "deviceClass": {
          "*": "deviceClass-&"
        }
      }
    }
    }
]
Matthew Warman
  • 3,234
  • 2
  • 23
  • 35