{"id":13516214,"url":"https://github.com/SelectTransform/st.js","last_synced_at":"2025-03-31T06:30:28.381Z","repository":{"id":52164708,"uuid":"105593259","full_name":"SelectTransform/st.js","owner":"SelectTransform","description":"JSON template over JSON","archived":false,"fork":false,"pushed_at":"2023-01-11T11:18:46.000Z","size":95,"stargazers_count":1226,"open_issues_count":29,"forks_count":63,"subscribers_count":21,"default_branch":"develop","last_synced_at":"2025-03-18T09:07:02.065Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://selecttransform.github.io/site/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SelectTransform.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}},"created_at":"2017-10-02T22:53:16.000Z","updated_at":"2025-02-18T21:12:33.000Z","dependencies_parsed_at":"2023-02-09T02:46:26.750Z","dependency_job_id":null,"html_url":"https://github.com/SelectTransform/st.js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SelectTransform%2Fst.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SelectTransform%2Fst.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SelectTransform%2Fst.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SelectTransform%2Fst.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SelectTransform","download_url":"https://codeload.github.com/SelectTransform/st.js/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246135758,"owners_count":20729056,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-08-01T05:01:20.396Z","updated_at":"2025-03-31T06:30:28.072Z","avatar_url":"https://github.com/SelectTransform.png","language":"JavaScript","readme":"# ST\n\nJSON Selector + Transformer\n\n- Website: [https://selecttransform.github.io/site](https://selecttransform.github.io/site)\n- Twitter: [@selecttransform](https://www.twitter.com/selecttransform)\n\n---\n\n![preview](https://gliechtenstein.github.io/images/st.gif)\n\n1. **Select:** Query any JSON tree to select exactly the subtree you are looking for.\n2. **Transform:** Transform any JSON object to another by parsing with a template, also written in JSON\n\nYou can also mix and match Select AND Transform to perform partial transform, modularize JSON objects, etc.\n\n# Features\n\n## 1. Select\n\nSelect a JSON object or its subtree that matches your criteria\n\n\u003e Step 1. Take any JSON object\n\n```js\nvar data = {\n  \"links\": [\n    { \"remote_url\": \"http://localhost\" },\n    { \"file_url\": \"file://documents\" },\n    { \"remote_url\": \"https://blahblah.com\" }\n  ],\n  \"preview\": \"https://image\",\n  \"metadata\": \"This is a link collection\"\n}\n```\n\n\u003e Step 2. Find all key/value pairs that match a selector function\n\n```js\nvar sel = ST.select(data, function(key, val) {\n  return /https?:/.test(val);\n})\n```\n\n\u003e Step 3. Get the result\n\n```js\nvar keys = sel.keys();\n//  [\n//    \"remote_url\",\n//    \"remote_url\",\n//    \"preview\"\n//  ]\n\nvar values = sel.values();\n//  [\n//    \"http://localhost\",\n//    \"https://blahblah.com\",\n//    \"https://image\"\n//  ]\n\nvar paths = sel.paths();\n//  [\n//    \"[\\\"links\\\"]\",\n//    \"[\\\"links\\\"]\",\n//    \"\"\n//  ]\n```\n\n## 2. Transform\n\nUse template to transform one object to another\n\n\u003e Step 1. Take any JSON object\n\n```js\nvar data = {\n  \"title\": \"List of websites\",\n  \"description\": \"This is a list of popular websites\"\n  \"data\": {\n    \"sites\": [{\n      \"name\": \"Google\",\n      \"url\": \"https://google.com\"\n    }, {\n      \"name\": \"Facebook\",\n      \"url\": \"https://facebook.com\"\n    }, {\n      \"name\": \"Twitter\",\n      \"url\": \"https://twitter.com\"\n    }, {\n      \"name\": \"Github\",\n      \"url\": \"https://github.com\"\n    }]\n  }\n}\n```\n\n\u003e Step 2. Select and transform with a template JSON object\n\n```js\nvar sel = ST.select(data, function(key, val){\n            return key === 'sites';\n          })\n          .transformWith({\n            \"items\": {\n              \"{{#each sites}}\": {\n                \"tag\": \"\u003ca href='{{url}}'\u003e{{name}}\u003c/a\u003e\"\n              }\n            }\n          })\n\n```\n\n\n\u003e Step 3. Get the result\n\n```js\nvar keys = sel.keys();\n//  [\n//    \"tag\",\n//    \"tag\",\n//    \"tag\",\n//    \"tag\"\n//  ]\n\nvar values = sel.values();\n//  [\n//    \"\u003ca href='https://google.com'\u003eGoogle\u003c/a\u003e\",\n//    \"\u003ca href='https://facebook.com'\u003eFacebook\u003c/a\u003e\",\n//    \"\u003ca href='https://twitter.com'\u003eTwitter\u003c/a\u003e\",\n//    \"\u003ca href='https://github.com'\u003eGithub\u003c/a\u003e\"\n//  ]\n\nvar objects = sel.objects();\n//  [\n//    {\n//      \"tag\": \"\u003ca href='https://google.com'\u003eGoogle\u003c/a\u003e\"\n//    }, {\n//      \"tag\": \"\u003ca href='https://facebook.com'\u003eFacebook\u003c/a\u003e\"\n//    }, {\n//      \"tag\": \"\u003ca href='https://twitter.com'\u003eTwitter\u003c/a\u003e\"\n//    }, {\n//      \"tag\": \"\u003ca href='https://github.com'\u003eGithub\u003c/a\u003e\"\n//    }\n//  ]\n\nvar root = sel.root();\n//  {\n//    \"items\": [{\n//      \"tag\": \"\u003ca href='https://google.com'\u003eGoogle\u003c/a\u003e\"\n//    }, {\n//      \"tag\": \"\u003ca href='https://facebook.com'\u003eFacebook\u003c/a\u003e\"\n//    }, {\n//      \"tag\": \"\u003ca href='https://twitter.com'\u003eTwitter\u003c/a\u003e\"\n//    }, {\n//      \"tag\": \"\u003ca href='https://github.com'\u003eGithub\u003c/a\u003e\"\n//    }]\n//  }\n```\n\n---\n\n# Usage\n\n## In a browser\n\n```js\n\u003cscript src=\"st.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\nvar parsed = ST.select({ \"items\": [1,2,3,4] })\n                .transformWith({\n                  \"{{#each items}}\": {\n                    \"type\": \"label\", \"text\": \"{{this}}\"\n                  }\n                })\n                .root();\n\u003c/script\u003e\n```\n\n## In node.js\n\n\u003e Install through npm:\n\n```bash\n$ npm install stjs\n```\n\n\u003e Use\n\n```js\nconst ST = require('st');\n\nconst parsed = ST.select({ \"items\": [1,2,3,4] })\n                .transformWith({\n                  \"{{#each items}}\": {\n                    \"type\": \"label\", \"text\": \"{{this}}\"\n                  }\n                })\n                .root();\n```\n\n### Learn more at [selecttransform.github.io/site](https://selecttransform.github.io/site)\n","funding_links":[],"categories":["JavaScript","📦 Legacy \u0026 Inactive Projects"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSelectTransform%2Fst.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSelectTransform%2Fst.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSelectTransform%2Fst.js/lists"}