Switch simplifies Morpheus option list creation by creating easy-to-
consume JSON files from your complex REST data sources

Switch performs preprocessing on JSON data. Designed to simplify Morpheus option list creation and management, Switch can fetch a target URL and parse it, creating name and value keys in a new JSON file according to the YAML configuration rules provided.

Switch can manage multiple source files, and, using a Time to Live (TTL) for each source it will refresh the data at the specified interval. Switch saves the data as a new JSON file in a location you specify. Any web server can serve it, you could also use the Dujour JSON/CSV data file server.

Formulating the JavaScript for Morpheus Option List REST translation scripts can be complex, while any JSON file which presents as an array of name and value keys, needs no translation script whatsoever since Morpheus is able to interpret it automatically.

So, Switch takes a complex JSON payload, which would require a translation script to parse in Morpheus, and creates a simple representation of the data needed for the option list.

Basic use, requires no translation script, more complicated use (such as dependent inputs) will mean any translation script is much simplified.

JSON that is option list ready

Switch extracts the data you need into name and value keys. No complex translation scripts are required for basic use.

Transform this data

{
  "items": {
    "item": [
      {
        "batters": {
          "batter": [
            {
              "id": "1001",
              "type": "Regular"
            },
            {
              "id": "1002",
              "type": "Chocolate"
            },
            {
              "id": "1003",
              "type": "Blueberry"
            },
            {
              "id": "1004",
              "type": "Devil's Food"
            }
          ]
        },
        "id": "0001",
        "name": "Cake",
        "ppu": 0.55,
        "topping": [
          {
            "id": "5001",
            "type": "None"
          },
          {
            "id": "5002",
            "type": "Glazed"
          },
          {
            "id": "5005",
            "type": "Sugar"
          },
          {
            "id": "5007",
            "type": "Powdered Sugar"
          },
          {
            "id": "5006",
            "type": "Chocolate with Sprinkles"
          },
          {
            "id": "5003",
            "type": "Chocolate"
          },
          {
            "id": "5004",
            "type": "Maple"
          }
        ],
        "type": "donut"
      }
    ]
  }
}

Into this data

[{
	"name": "Regular",
	"value": "1001"
}, {
	"name": "Chocolate",
	"value": "1002"
}, {
	"name": "Blueberry",
	"value": "1003"
}, {
	"name": "Devil's Food",
	"value": "1004"
}]

So you don't need to write this

// extract data to name and value using the JavaScript

for (var x = 0; x < data.items.item[0].batters.batter.length; x++) {
  results.push(
     {
        name: data.items.item[0].batters.batter[x].type,
        value: data.items.item[0].batters.batter[x].id
     }
  );
}

Get started with Switch

Switch is simple to install and configure...

Install the application

Switch is available for Linux and Mac OS and can be found on Github. It may be hosted on the same server as the Morpheus Appliance or on a separate VM.

Download the latest release to your server and unpack the gzipped package.

wget https://github.com/spoonboy-io/switch/releases/download/v0.0.1/switch_0.0.1_Linux_x86_64.tar.gz
tar -xvf switch_0.0.1_Linux_x86_64.tar.gz

Run the Switch application

./switch

Configure a JSON source

Create a `sources.yaml` file in the same directory as Switch and configure it for your JSON source. A sample file is available here.

Switch will fetch and process the data, to make a new json file qccording to this configuration

---
- source:
    description: Some blog posts (array)
    url: https://jsonplaceholder.typicode.com/posts
    token:
    extract:
        name: title
        value: id
    ttl: 5
    save:
        folder: test
        filename: test.json

Serve your simplified JSON data

Switch can save data to any location on the same server, perhaps a webserver. If you run Dujour on the same VM, you can also save it there, and Dujour will serve it.

    save:
        folder: test
        filename: test.json

Switch will use the TTL value (specified in minutes) to expire and refresh the data.

    ttl: 5
golang morpheus json option lists rest