{"id":46975554,"url":"https://github.com/spoonboy-io/switch","last_synced_at":"2026-03-11T12:37:53.358Z","repository":{"id":65518277,"uuid":"592832583","full_name":"spoonboy-io/switch","owner":"spoonboy-io","description":"Preprocess JSON to name and value keys for Morpheus","archived":false,"fork":false,"pushed_at":"2023-04-01T11:46:54.000Z","size":42,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-21T03:15:01.604Z","etag":null,"topics":["inputs","json","morpheus","option-lists"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spoonboy-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-24T16:25:56.000Z","updated_at":"2023-03-31T13:25:11.000Z","dependencies_parsed_at":"2024-06-21T02:07:20.740Z","dependency_job_id":"271376a7-93aa-42a6-9be1-42d2e8a8ccfd","html_url":"https://github.com/spoonboy-io/switch","commit_stats":{"total_commits":17,"total_committers":1,"mean_commits":17.0,"dds":0.0,"last_synced_commit":"2e76ae9a8b70e9b8eed564daec1beacf4e9f047c"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/spoonboy-io/switch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spoonboy-io%2Fswitch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spoonboy-io%2Fswitch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spoonboy-io%2Fswitch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spoonboy-io%2Fswitch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spoonboy-io","download_url":"https://codeload.github.com/spoonboy-io/switch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spoonboy-io%2Fswitch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30381022,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T06:09:32.197Z","status":"ssl_error","status_checked_at":"2026-03-11T06:09:17.086Z","response_time":84,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["inputs","json","morpheus","option-lists"],"created_at":"2026-03-11T12:37:52.783Z","updated_at":"2026-03-11T12:37:53.350Z","avatar_url":"https://github.com/spoonboy-io.png","language":"Go","readme":"# Switch\n\n### Preprocess JSON to `name` and `value` keys for Morpheus \n\n[![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/spoonboy-io/switch?style=flat-square)](https://go.dev/)\n[![Go Report Card](https://goreportcard.com/badge/github.com/spoonboy-io/switch?style=flat-square)](https://goreportcard.com/report/github.com/spoonboy-io/switch)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/spoonboy-io/switch/build.yml?branch=master\u0026style=flat-square)](https://github.com/spoonboy-io/switch/actions/workflows/build.yml)\n[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/spoonboy-io/switch/unit_test.yml?branch=master\u0026label=tests\u0026style=flat-square)](https://github.com/spoonboy-io/switch/actions/workflows/unit_test.yml)\n[ ![ GitHub Release Date ](https://img.shields.io/github/release-date/spoonboy-io/switch?style=flat-square) ](https://github.com/spoonboy-io/switch/releases)\n[![GitHub commits since latest release (by date)](https://img.shields.io/github/commits-since/spoonboy-io/switch/latest?style=flat-square)](https://github.com/spoonboy-io/switch/commits)\n[![GitHub](https://img.shields.io/github/license/spoonboy-io/switch?label=license\u0026style=flat-square)](LICENSE)\n\n\n## About\n\nSwitch performs preprocessing on JSON data. Designed to simplify Morpheus option list creation and management,\nSwitch can fetch a target URL and parse it, creating \n`name` and `value` keys in a new JSON file according to the YAML configuration rules provided.\n\nSwitch can manage multiple source files, and, using a Time to Live (TTL) for each source it will refresh the data\nat the specified interval.\n\nSwitch saves the data as a new JSON file in a location you specify. Any web server can serve it, you could also use\nthe [Dujour JSON/CSV data file server](https://github.com/spoonboy-io/dujour).\n\n\n## Why?\n\nFormulating the JavaScript for Morpheus Option List REST translation scripts can be complex, while any JSON file which presents\nas an array of `name` and `value` keys, needs no translation script whatsoever since Morpheus is able to interpret it automatically.\n\nSo, Switch takes a complex JSON payload, which would require a translation script to parse in Morpheus, and creates a\nsimple representation of the data needed for the option list.\n\nBasic use, requires no translation script, more complicated use (such as dependent inputs) will mean any translation \nscript is much simplified.\n\n## Releases\n\nYou can find the [latest software here](https://github.com/spoonboy-io/switch/releases/latest).\n\n## Usage\n\nSwitch will look for and parse a [sources.yaml file](https://github.com/spoonboy-io/switch/blob/master/sources.yaml) which has the following format:\n\n```yaml\n---\n- source:\n    description: Some blog posts (array)\n    url: https://jsonplaceholder.typicode.com/posts\n    token: Bearer xxxxx-xxx-xxx\n    extract:\n      root:\n      name: title\n      value: id\n    ttl: 5 # minutes\n    save:\n      folder: test\n      filename: test.json\n```\n\nThe above configuration creates this file `./test/test.json` locally:\n\n```json\n\n[{\n\t\"name\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\",\n\t\"value\": 1\n}, {\n\t\"name\": \"qui est esse\",\n\t\"value\": 2\n}, {\n\t\"name\": \"ea molestias quasi exercitationem repellat qui ipsa sit aut\",\n\t\"value\": 3\n}, {\n\t\"name\": \"eum et est occaecati\",\n\t\"value\": 4\n}, {\n\t\"name\": \"nesciunt quas odio\",\n\t\"value\": 5\n},\n  \n  // ... abbreviated\n  \n  {\n\t\"name\": \"at nam consequatur ea labore ea harum\",\n\t\"value\": 100\n}]\n```\n\nA similar config, which adds a root of \"batter\", can parse remote JSON like this:\n\n```json\n{\n  \"items\": {\n    \"item\": [\n      {\n        \"batters\": {\n          \"batter\": [\n            {\n              \"id\": \"1001\",\n              \"type\": \"Regular\"\n            },\n            {\n              \"id\": \"1002\",\n              \"type\": \"Chocolate\"\n            },\n            {\n              \"id\": \"1003\",\n              \"type\": \"Blueberry\"\n            },\n            {\n              \"id\": \"1004\",\n              \"type\": \"Devil's Food\"\n            }\n          ]\n        },\n        \"id\": \"0001\",\n        \"name\": \"Cake\",\n        \"ppu\": 0.55,\n        \"topping\": [\n          {\n            \"id\": \"5001\",\n            \"type\": \"None\"\n          },\n          {\n            \"id\": \"5002\",\n            \"type\": \"Glazed\"\n          },\n          {\n            \"id\": \"5005\",\n            \"type\": \"Sugar\"\n          },\n          {\n            \"id\": \"5007\",\n            \"type\": \"Powdered Sugar\"\n          },\n          {\n            \"id\": \"5006\",\n            \"type\": \"Chocolate with Sprinkles\"\n          },\n          {\n            \"id\": \"5003\",\n            \"type\": \"Chocolate\"\n          },\n          {\n            \"id\": \"5004\",\n            \"type\": \"Maple\"\n          }\n        ],\n        \"type\": \"donut\"\n      }\n    ]\n  }\n}\n```\n\nTo this:\n\n```json\n[{\n\t\"name\": \"Regular\",\n\t\"value\": \"1001\"\n}, {\n\t\"name\": \"Chocolate\",\n\t\"value\": \"1002\"\n}, {\n\t\"name\": \"Blueberry\",\n\t\"value\": \"1003\"\n}, {\n\t\"name\": \"Devil's Food\",\n\t\"value\": \"1004\"\n}]\n```\n\nWhich avoids the need to use **any** translation script, which would otherwise look like this if parsing the original file:\n\n```javascript\nfor (var x = 0; x \u003c data.items.item[0].batters.batter.length; x++) {\n  results.push({\n    name: data.items.item[0].batters.batter[x].type, \n    value: data.items.item[0].batters.batter[x].id\n  });\n}\n```\n\n### Installation\nGrab the tar.gz or zip archive for your OS from the [releases page](https://github.com/spoonboy-io/switch/releases/latest).\n\nUnpack it to the target host, and then start the application.\n\n```\n./switch\n```\nOr with debug output, which will show retrieved source, parsed output and heap allocated, in addition to normal log\nand error reporting..\n\n```\n./switch -debug\n```\n\nOr with nohup..\n\n```\nnohup ./switch \u0026\n```\n\n### TODO\n\n- Unit tests only cover the extraction routines\n- Only manually tested with unauthenticated GET requests at this time\n- The extraction code, caters for simple arrays and objects keys which store an array\n\n### License\nLicensed under [Mozilla Public License 2.0](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspoonboy-io%2Fswitch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspoonboy-io%2Fswitch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspoonboy-io%2Fswitch/lists"}