{"id":20019746,"url":"https://github.com/weavedb/fpjson","last_synced_at":"2025-10-26T19:19:56.381Z","repository":{"id":188521062,"uuid":"532257849","full_name":"weavedb/fpjson","owner":"weavedb","description":"Language-Agnostic Functional Programming in JSON","archived":false,"fork":false,"pushed_at":"2023-08-15T16:55:29.000Z","size":1275,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-08T14:12:39.876Z","etag":null,"topics":["functional-programming","json","ramdajs"],"latest_commit_sha":null,"homepage":"https://fpjson.weavedb.dev","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/weavedb.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-03T12:45:43.000Z","updated_at":"2024-09-06T22:19:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"ec86cc2b-ce55-44a7-81ba-b26f7660d781","html_url":"https://github.com/weavedb/fpjson","commit_stats":null,"previous_names":["weavedb/fpjson"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weavedb%2Ffpjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weavedb%2Ffpjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weavedb%2Ffpjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weavedb%2Ffpjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weavedb","download_url":"https://codeload.github.com/weavedb/fpjson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252414506,"owners_count":21744114,"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":["functional-programming","json","ramdajs"],"created_at":"2024-11-13T08:28:37.194Z","updated_at":"2025-10-26T19:19:56.375Z","avatar_url":"https://github.com/weavedb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](./assets/cover.png)\n\n# FPJSON\n\n[FPJSON](https://fpjson.weavedb.dev) is a programming language agnostic JSON-based functional programming language.\n\n- The whole code is just a JSON array\n- Functional Programming\n- No overhead due to programming language implementation details\n\nIn other words, you don't have to worry about any programming language specifications.\n\nInstead you can just focus on building pure logics for data manipuration.\n\nSince it's just a JSON array, it can be ported to any programming language environment.\n\n#### Some Examples\n\n```javascript\n/* add */\n[\"add\", 1, 2] // = 3\n\n/* difference */\n[\"difference\", [1, 2, 3], [3, 4, 5]] = [1, 2]\n\n/* map */\n[[\"map\", [\"inc\"]], [1, 2, 3]] // = [4, 5, 6]\n\n/* compose */\n[[\"compose\", [\"map\", [\"inc\"]], [\"difference\"]], [1, 2, 3], [3, 4, 5]] // = [2, 3]\n```\nThere are more than 250 pre-defined functions. And you can further extend that library.\n\n## Install\n\nFor now the parser is only implemented in JavaScript and it borrows heavily from [Ramda.js](https://ramdajs.com/).\n\nIn fast, you can use most of the functions in Ramda with FPJSON.\n\n```bash\nyarn add fpjson-lang\n```\n\n## Usage\n\nIt couldn't be simpler.\n\n```javascript\nimport fpjson from \"fpjson-lang\"\n\nconst one_plus_two = fpjson([\"add\", 1, 2]) // = 3\n```\n\n## Syntax\n\nYou should familiarize yourself with Ramda which enables Haskell-like functional programming with JS. You can use most of the powerful ramda functions with point-free style in JSON.\n\nThe first element in an array is a function.\n\n```javascript\n[\"add\", 1, 2] // add(1, 2)\n```\n\nTo curry a function, nest it.\n\n```javascript\n[[\"add\", 1], 2] // add(1)(2)\n```\n\nA function always needs to be wrapped with `[]` and to be the first element in the array.\n\n```javascript\n[[\"map\", [\"inc\"]], [1, 2, 3]] // map(inc)([1, 2, 3])\n```\n\nThis is an error because `inc` is imterpreted as `String`.\n```javascript\n[[\"map\", \"inc\"], [1, 2, 3]] // map(\"inc\")([1, 2, 3])\n```\n\nPoint-free style means you cannot write something like this with the JSON format.\n\n```javascript\nsortBy((v)=\u003e v.age)(people) // ramdajs\n```\n\nIt's because you cannot write arbitrary JS lines such as `(v)=\u003e v.age`.\n\nInstead, you can achieve the same using another ramda funciton `prop`.\n\n```javascript\nsortBy(prop(\"age\"), people) // ramdajs\n[\"sortBy\",[\"prop\", \"age\"], people] // FPJSON\n```\n\n## Reserved First Words\n\nBy placing a reserved word in the first spot of an array, you can access the pre-built features.\n\nThere are just 6 of them.\n\n#### \"[]\"\n\nTo create an array of functions without executing them, place `\"[]\"` in the first spot, otherwise the `[\"lte\", 2]` function will be executed with `[\"gt\", 2]` before `-3` is passed.\n\n```javascript\n[[\"anyPass\", [\"[]\", [\"lte\", 2], [\"gt\", 2]]], -3] // anyPass(lte(2), gt(2))(-3)\n```\n\n#### \"typ\"\n\nTo create a type object such as `Number`, `Boolean`, `String`, `Array`, and `Object`.\n```javascript\n[\"is\", [\"typ\", \"String\"], \"abc\"] // is(String, \"abc\")\n```\n\n#### \"reg\"\n\nTo create a `RegExp`.\n```javascript\n[\"test\", [\"reg\", \"a\", \"i\"], \"ABC\"] // test(new RegExp(\"a\", \"i\"), \"ABC\")\n```\n\n#### \"$\"\n\nYou can pass a store object as the second argument to `fpjson`.\n\nTo access previously defined variables, use `\"$\"`.\n\n```javascript\nfpjson([\"add\", [\"$\", \"num1\"], 1], { \"num\": 1 }) // 2\n```\n\n#### \"let\"\n\nPure functional programming without any side-effects is easy to get extremely complex and entangled even for simple logics.\n\n`\"let\"` inserts global variables to ease up the unnecessary complexisities.\n\n```javascript\n[\"let\", \"num1\", 1] // let var1 = 1\n```\n\n#### \"var\"\n\n`var` works just like `$` except that `var` needs another argument to invoke.\n\nThe last argument can be anything since it will be ignored.\n\nNote that you cannot access a new value within the same composition where it was defined. \n\n```javascript\nlet vars = {}\nfpjson([\"let\", \"num1\", 1], vars) // vars = { \"num1\" : 1 }\nfpjson([\"add\", [\"var\", \"num1\", true], 1], vars) // 2\n```\n\n`var` is especially convenient in a composition to switch the tracked value..\n\n```javascript\nfpjson([[\n  \"pipe\",\n  [\"add\", 1], // add 1 to 1\n  [\"let\", \"num1\"], // store 2 to num1\n  [\"var\", \"num2\"] // switch the ctx to num2, var(\"num2\", 2), but 2 ignored\n], 1]),{ num2: 4 }) // =\u003e 4 is the final result\n```\n\nThis pipeline add `1` to the initial value `1`, store it to `num1`, then switch the context to `num2`.\n\n#### Dynamic Variables\n\nVariable names can be dinamically specified with `$dynamic_path`.\n\n```javascript\nlet vars = {}\nfpjson([\"let\", \"num1\", 1], vars) // vars = { \"num1\" : 1 }\nfpjson([\"let\", \"ln\", \"num1\"], vars) // vars = { \"num1\" : 1, \"ln\" : \"num1\" }\nfpjson([\"add\", [\"$, \"$ln\"], 1], vars) // 2\n```\n\n#### Dot Notation\n\nNested fields can be accessed with `.`.\n\n```javascript\nlet vars = {}\nfpjson([\"let\", \"o\", { num: 1 }], vars) // vars = { \"o\" : { \"num\": 1 } }\nfpjson([\"var\", \"o.num\", true ], vars) // 1\n```\n\n## Who is Using FPJSON?\n\nFPJSON is used to define access control rules and cron jobs in [WeaveDB](https://weavedb.weavedb.dev/) - Arweave-based decentralized NoSQL Database. FPJSON allows super rich and complex programming logics to be stored as JSON data on smart contracts, which opens up a whole new pradigm to dapp development.\n\nFPJSON is also to be used for natural language generation algorithms, which will lead to the next-gen AI paradigm to revolutionize the human languages.\n\n## Tutorials\n\nLearning functional programming is pretty challenging. So we created interactive tutorials and an exam to make sure you can familiarize yourself with all the core functions with ease!\n\nGoing through the tutorials will install a new framework in your brain and make you a better programmer in general even if you never need FPJSON.\n\nIt's not so much about languages, but about how your brain agnostically operates on data structures.\n\n- [fpjson.weavedb.dev](https://fpjson.weavedb.dev)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweavedb%2Ffpjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweavedb%2Ffpjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweavedb%2Ffpjson/lists"}