{"id":17766582,"url":"https://github.com/floatdrop/jsot","last_synced_at":"2026-01-20T03:34:20.481Z","repository":{"id":18642018,"uuid":"21848587","full_name":"floatdrop/jsot","owner":"floatdrop","description":"JSON object transformation","archived":false,"fork":false,"pushed_at":"2014-07-22T06:34:05.000Z","size":400,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T01:31:42.401Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/floatdrop.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-15T06:12:32.000Z","updated_at":"2016-03-07T19:08:58.000Z","dependencies_parsed_at":"2022-09-15T01:21:34.983Z","dependency_job_id":null,"html_url":"https://github.com/floatdrop/jsot","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fjsot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fjsot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fjsot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fjsot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/floatdrop","download_url":"https://codeload.github.com/floatdrop/jsot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247645839,"owners_count":20972551,"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-10-26T20:32:50.704Z","updated_at":"2026-01-20T03:34:20.455Z","avatar_url":"https://github.com/floatdrop.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSOT - JSON object transformation [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url] [![Coveralls Status][coveralls-image]][coveralls-url]\n\nThis is implementation of some sort of XSLT paradigm, but with JSON object instead of XML.\n\n## Usage\n\nSome usage examples can be found in `test/benchmark.js` folder. Here one of those:\n\n```js\nvar jsot = new JSOT();\n\njsot.match('block', function(context) {\n    return '\u003c' + context.block + '\u003e' + this.apply(context.content) + '\u003c/' + context.block + '\u003e';\n});\n\njsot.apply({ block: 'html', content: [ 'some', 'tags' ] });\n// Returns '\u003chtml\u003esometags\u003c/html\u003e'\n```\n\n\n## API\n\nThis is pre-alpha version, so API will be changed or modified. Stay tuned!\n\n### JSOT constructor\n\nTakes no parameters. Just use it `var jsot = new JSOT()`.\n\n#### JSOT._current\n\nStores additional information about current processed object:\n\n * `JSOT._current.position` - If element in array, it will contain its position (counting from zero).\n * `JSOT._current.length` - If element in array, it will contain length of the array.\n * `JSOT._current.element` - Stores current processed object (same as matcher argument). Useful for wrappers.\n\n### JSOT.match(pattern, matcher)\n\nStores matcher function, that will be applied on json, when pattern is statisfied.\n\n* __pattern__ - Can be `string` or `object`.\n* __matcher__ - Function with next signature: `function (context) { ... }`. It gets context and returns transformated result. Matcher is called with context of `JSOT` object.\n\n##### Context\n\nContext is the part of the json object, that matched pattern including fields, that caused match. For example:\n\n```js\nvar jsot = new JSOT();\n\njsot.match('head', function (context) {\n    console.log(context); // -\u003e { head: 'title', body: 'text' }\n});\n\njsot.apply({ head: 'title', body: 'text' });\n```\n\n##### Result\n\nResult can be one of those types:\n\n * `string` - final result of transformation\n * `object` - new json object, on which apply will be called again.\n * `Array` - Array with results that will be transformed (in the end) in strings and concatinated.\n\n```js\nvar jsot = new (require('./index.js'));\n\njsot.match('list', function (context) {\n    return context.list.split(' ').concat('again'); // Returning array\n});\n\njsot.apply({ list: 'Some concatinated words' }); // -\u003e 'Someconcatinatedwordsagain'\n```\n\n### JSOT.apply(object)\n\nApply methods performs recursive transformation with defined matchets by `JSOT.match` method.\nReturns string with transformed result.\n\n## Benchmarking results\n\nBenchmarks of internal functionality.\n\n```\n                      apply without matches\n     101,707,826 op/s » simple value\n       2,872,773 op/s » short array\n      30,948,360 op/s » object with out matching property\n      30,942,242 op/s » object with matching property\n\n                      apply with match\n      87,199,363 op/s » simple value\n       2,957,711 op/s » short array\n      22,988,907 op/s » object with out matching property\n       2,160,836 op/s » object with matching property\n\n                      apply with multiple matches\n      88,600,067 op/s » simple value\n       2,908,635 op/s » short array\n       7,156,239 op/s » object with out matching property\n       1,599,449 op/s » object with matching property\n\n                      compilePattern\n      77,000,156 op/s » simple values\n      74,135,502 op/s » simple objects\n      42,939,839 op/s » bh object\n      32,273,702 op/s » bh complex object\n\n                      recursiveMatching\n      90,930,827 op/s » simple values\n      18,900,108 op/s » simple objects\n       7,933,644 op/s » bh object\n       4,263,322 op/s » bh complex object\n\n                      staticFunction\n      45,792,933 op/s » block\n      18,946,571 op/s » block_mod\n      34,840,615 op/s » block__elem\n      11,880,409 op/s » block_mod__elem_mod\n```\n\n[npm-url]: https://npmjs.org/package/jsot\n[npm-image]: http://img.shields.io/npm/v/jsot.svg\n\n[travis-url]: https://travis-ci.org/floatdrop/jsot\n[travis-image]: http://img.shields.io/travis/floatdrop/jsot.svg\n\n[depstat-url]: https://david-dm.org/floatdrop/jsot\n[depstat-image]: https://david-dm.org/floatdrop/jsot.svg?theme=shields.io\n\n[coveralls-url]: https://coveralls.io/r/floatdrop/jsot\n[coveralls-image]: http://img.shields.io/coveralls/floatdrop/jsot/master.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloatdrop%2Fjsot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffloatdrop%2Fjsot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloatdrop%2Fjsot/lists"}