{"id":13406898,"url":"https://github.com/aykutkardas/Json-Function","last_synced_at":"2025-03-14T11:30:48.318Z","repository":{"id":38274133,"uuid":"118310542","full_name":"aykutkardas/Json-Function","owner":"aykutkardas","description":"It allows you to use methods such as schema, innerJoin, where, limit, select, orderBy on JSON data.","archived":false,"fork":false,"pushed_at":"2023-09-27T20:35:38.000Z","size":607,"stargazers_count":752,"open_issues_count":4,"forks_count":34,"subscribers_count":24,"default_branch":"main","last_synced_at":"2024-10-22T19:18:48.182Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://worn.gitbook.io/json-function/","language":"TypeScript","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/aykutkardas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"aykutkardas","patreon":"aykutkardas"}},"created_at":"2018-01-21T06:27:38.000Z","updated_at":"2024-09-12T18:26:52.000Z","dependencies_parsed_at":"2023-10-20T18:11:11.743Z","dependency_job_id":null,"html_url":"https://github.com/aykutkardas/Json-Function","commit_stats":{"total_commits":232,"total_committers":5,"mean_commits":46.4,"dds":0.04741379310344829,"last_synced_commit":"169c098291dd3be2ef63fc69a50e91ab9f7d84f0"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aykutkardas%2FJson-Function","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aykutkardas%2FJson-Function/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aykutkardas%2FJson-Function/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aykutkardas%2FJson-Function/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aykutkardas","download_url":"https://codeload.github.com/aykutkardas/Json-Function/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243569145,"owners_count":20312367,"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-07-30T19:02:42.428Z","updated_at":"2025-03-14T11:30:47.509Z","avatar_url":"https://github.com/aykutkardas.png","language":"TypeScript","funding_links":["https://github.com/sponsors/aykutkardas","https://patreon.com/aykutkardas"],"categories":["TypeScript","others"],"sub_categories":[],"readme":"# Json Function\n\n[![npm](https://img.shields.io/npm/v/json-function?color=%234fc921)](https://www.npmjs.com/package/json-function)\n[![License](https://img.shields.io/badge/License-MIT-green.svg?color=%234fc921)](https://opensource.org/licenses/MIT)\n[![Build Status](https://github.com/aykutkardas/Json-Function/workflows/Test/badge.svg?color=%234fc921)](https://github.com/aykutkardas/Json-Function/actions)\n\n## [Documentation](https://worn.gitbook.io/json-function/) • [Changelog](https://worn.gitbook.io/json-function/changelog)\n\nLets you use where, limit, select, orderBy, and more in JSON data.\n\n## Install\n\n```\nnpm install json-function\n```\n\nor\n\n```\nyarn add json-function\n```\n\n# Usage\n\n## JsonFunction • [documentation](https://worn.gitbook.io/json-function/)\n\nJson-Function provides a lot of useful functions especially for your json data. It contains the methods you need too much to eliminate unnecessary code repetition.\n\nYou can use the Json-Function methods separately, but it is possible to use them all together. You can also chain it.\n\nChaining\n\n```js\nimport JsonFunction from \"json-function\";\n\nconst result = JsonFunction\n  .where({ completed: false })\n  .select([\"title\", \"completed\"])\n  .orderBy(\"title\", \"DESC\")\n  .limit(2)\n  .get(data);\n```\n\nor Basic\n\n```js\nimport JsonFunction from \"json-function\";\n\nJsonFunction.where({ completed: false });\nJsonFunction.select([\"title\", \"completed\"]);\nJsonFunction.orderBy(\"title\", \"DESC\");\nJsonFunction.limit(2);\nconst result = JsonFunction.get(data);\n```\n\nor create a query and use it at any time.\n```js\nconst queryTwoIncompleteTasks = JsonFunction\n  .where({ completed: false })\n  .select([\"title\", \"completed\"])\n  .limit(2)\n  .getQuery();\n  \n```\n\nQuery usage\n```js\nJsonFunction.setQuery(queryTwoIncompleteTasks).get(data);\n// or\nJsonFunction.get(data, { query: queryTwoIncompleteTasks });\n```\n\n\n# Methods\n\nInstead of an entire \"class\", you can use only the methods you need.\n\n## innerJoin • [documentation](https://worn.gitbook.io/json-function/functions/inner-join)\n\nThe \"innerJoin\" function is used to join two arrays.\n\n\n```js\nimport { innerJoin } from \"json-function\";\n\ninnerJoin(data, data2, \"id\", \"userId\");\n```\n\n## schema • [documentation](https://worn.gitbook.io/json-function/functions/schema)\n\nThe \"Schema\" function is a great way to reconfigure your json data and make it your own.\n\n```js\nimport { schema } from \"json-function\";\n\nschema(data, {\n  book: {\n    id: \"id\",\n    title: \"title\"\n  },\n  firstname: \"user.firstname\",\n  lastname: \"user.lastname\"\n});\n```\n\nUse \"callback\" for advanced conversions.\n\n```js\nschema(data, (sc) =\u003e ({\n  id: \"id\",\n  fullName: sc.join(\"user.firstname\", \"user.lastname\")\n}));\n```\n\nCustom separator\n\n```js\nschema(data, (sc) =\u003e ({\n  id: \"id\",\n  fullName: sc.join(\"user.firstname\", \"user.lastname\", { separator: \"_\" })\n}));\n```\n\nUse your own special function.\n```js\nschema(data, (sc) =\u003e ({\n  id: \"id\",\n  fullName: sc.custom(\n    (firstname, lastname) =\u003e `${firstname.toUpperCase()} ${lastname.toUpperCase()}`,\n    \"user.firstname\",\n    \"user.lastname\"\n  ),\n}))\n```\n\nExample\n```js\nschema(data, (sc) =\u003e ({\n  id: \"id\",\n  createdAt: sc.custom(\n    (createdAt) =\u003e moment(createdAt).format(\"DD/MM/YYYY\"),\n    \"createdAt\",\n  ),\n}))\n```\n## where • [documentation](https://worn.gitbook.io/json-function/functions/where) • [samples](https://nj0ql.csb.app/)\n\nThe \"Where\" function provides a comfortable method for filtering a json data.\n\n```js\nimport { where } from \"json-function\";\n\n// Single\n// (completed === false)\nwhere(data, { completed: false });\n\n// Multiple (or)\n// (completed === false || userId === 2)\nwhere(data, [{ completed: false }, { userId: 2 }]);\n\n// Deep\n// (address.city === \"New York\")\nwhere(data, { \"address.city\": \"New York\" }, { deep: true });\n```\n\nUse \"callback\" for advanced filter.\n\n```js\n// id \u003c= 3\nwhere(data, (wh) =\u003e ({\n  id: wh.lte(3),\n}));\n```\n\nOther **wh** methods.\n```js\nwh.lte(3)             // value \u003c= 3\nwh.lt(3)              // value \u003c  3\nwh.gte(3)             // value \u003e= 3\nwh.gt(3)              // value \u003e  3\nwh.between(3,5)       // value \u003e= 3 \u0026\u0026 value \u003c= 5\nwh.eq(\"3\")            // value == 3\nwh.ne(\"3\")            // value != 3\nwh.in(\"test\")         // value.includes(\"test\")\nwh.nin(\"test\")        // !value.includes(\"test\")\nwh.oneOf([1, 2, 3])  // [1, 2, 3].includes(value)\n```\n\n## select • [documentation](https://worn.gitbook.io/json-function/functions/select)\n\nThe \"Select\" function is a practical method where you only get the desired fields of a json data.\n\n```js\nimport { select } from \"json-function\";\n\n// Single\nselect(data, \"title\");\n\n// Multiple\nselect(data, [\"title\", \"completed\"]);\n```\n\n## limit • [documentation](https://worn.gitbook.io/json-function/functions/limit)\n\n\"Limit\" is used to get a limited number of elements from a json data. Almost javascript works like slice() but it is much easier and clearer.\n\n```js\nimport { limit } from \"json-function\";\n\n// limit\nlimit(data, 2);\n\n// limit and Start\nlimit(data, 2, 2);\n```\n\n## orderBy • [documentation](https://worn.gitbook.io/json-function/functions/order-by)\n\nWith the \"orderBy\" function you can reorder the data in your json array.\n\n```js\nimport { orderBy } from \"json-function\";\n\norderBy(data, \"title\", \"DESC\");\n\norderBy(data, \"user.firstname\", \"DESC\", { deep: true });\n```\n\n## search • [documentation](https://worn.gitbook.io/json-function/functions/search)\n\nSearch over fields of objects.\n\n```js\nimport { search } from \"json-function\";\n\n// Syntax: search(data: Object[], key: any, fields: string | string[], options?);\n\n// single field\nsearch(data, \"key\", \"description\");\n\n// multiple field\nsearch(data, \"key\", [\"user.firstName\", \"description\"]);\n\n// case sensitive\nsearch(data, \"key\", \"description\", { caseSensitive: false });\n```\n\n## toArray • [documentation](https://worn.gitbook.io/json-function/functions/to-array)\n\nConverts objects into meaningful sequences.\n\n\n```js\nimport { toArray } from \"json-function\";\n\n// default key \"uid\"\ntoArray(data);\n\n// custom key\ntoArray(data, { key: \"_id_\" });\n```\n\n## transform • [documentation](https://worn.gitbook.io/json-function/functions/transform)\nJSON converts the snake_case keys in your data to camelCase.\n\n```js\nimport { transform } from \"json-function\";\n\ntransform(data);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faykutkardas%2FJson-Function","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faykutkardas%2FJson-Function","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faykutkardas%2FJson-Function/lists"}