{"id":13740016,"url":"https://github.com/nissy-dev/babel-plugin-object-to-json-parse","last_synced_at":"2025-05-08T19:35:23.068Z","repository":{"id":37035009,"uuid":"194471726","full_name":"nissy-dev/babel-plugin-object-to-json-parse","owner":"nissy-dev","description":"This plugin converts object literal to JSON.parse","archived":true,"fork":false,"pushed_at":"2023-01-01T08:03:39.000Z","size":917,"stargazers_count":159,"open_issues_count":3,"forks_count":12,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-02T19:05:55.523Z","etag":null,"topics":["babel-plugin","json-parse"],"latest_commit_sha":null,"homepage":"","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/nissy-dev.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":"2019-06-30T03:44:25.000Z","updated_at":"2024-01-12T18:09:36.000Z","dependencies_parsed_at":"2023-01-31T21:15:17.332Z","dependency_job_id":null,"html_url":"https://github.com/nissy-dev/babel-plugin-object-to-json-parse","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nissy-dev%2Fbabel-plugin-object-to-json-parse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nissy-dev%2Fbabel-plugin-object-to-json-parse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nissy-dev%2Fbabel-plugin-object-to-json-parse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nissy-dev%2Fbabel-plugin-object-to-json-parse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nissy-dev","download_url":"https://codeload.github.com/nissy-dev/babel-plugin-object-to-json-parse/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224593864,"owners_count":17337185,"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":["babel-plugin","json-parse"],"created_at":"2024-08-03T04:00:41.330Z","updated_at":"2024-11-15T09:30:57.748Z","avatar_url":"https://github.com/nissy-dev.png","language":"JavaScript","readme":"# babel-plugin-object-to-json-parse 🚀\n\n![release](https://github.com/nissy-dev/babel-plugin-remove-react-fc-and-vfc/actions/workflows/release.yml/badge.svg)\n[![License: MIT](https://img.shields.io/github/license/nd-02110114/babel-plugin-object-to-json-parse.svg)](https://opensource.org/licenses/MIT)\n[![npm version](https://badge.fury.io/js/babel-plugin-object-to-json-parse.svg)](https://badge.fury.io/js/babel-plugin-object-to-json-parse)\n\n\nThis repository is inspired by [this article](https://v8.dev/blog/cost-of-javascript-2019#json)\n\n\u003e As long as the JSON string is only evaluated once, the JSON.parse approach is much faster compared to the JavaScript object literal, especially for cold loads.\n\n## Object to JSON.parse\n\nThis plugin converts from object literal to JSON.parse\n\n```js\n// before\nconst data = { foo: 42, bar: 1337 };\n\n// after\nconst data = JSON.parse('{\"foo\":42,\"bar\":1337}');\n```\n\n## How to use\n\n### Install\n\n```sh\n$ npm install babel-plugin-object-to-json-parse -D\nor\n$ yarn add babel-plugin-object-to-json-parse -D\n```\n\n### setup `.babelrc`\n\n```json\n{\n  \"plugins\": [\"object-to-json-parse\"]\n}\n```\n\n\n### Options \n#### `minJSONStringSize` (`number`, defaults to `1024`)\n\nThe `minJSONStringSize` option will prevent the plugin from replacing an expression if the length of the JSON string given to `JSON.parse` is smaller than `minJSONStringSize`. For example, the following ensures all replacements have a string size of at least 1kb.\n\n```json\n{\n  \"plugins\": [\n    [\"object-to-json-parse\", {\n      \"minJSONStringSize\": 1024\n    }]\n  ]\n}\n```\n\n## Caution!!\n### this plugin may not be production ready\nI just made this plugin for my understanding about AST and babel plugin.\n\n### this plugin doesn't support partially JSON expression\n\nI decided not to support partially JSON expression like below.\n\n\u003e Partially JSON expressions such as [notValid, {isValid:true}] ensuring {isValid:true} is transformed.\n\n```\nconst data = { bar: invalid_object, foo: 'foo' }\n↓\nconst data = { bar: invalid_object, JSON.parse('{\"foo\": \"foo\"}')}\n```\n\nThis is because I think most large objects are not partially JSON expressions. **JSON.parse() is much faster in the case that object is 10 kB or larger. Converting small object to JSON.parse expression is not meaningful.**\n\n### this plugin produces output that only works in modern environments (e.g. Node.js v10+)\n\nI don't care about some backwards compatibilities like [this issue](https://github.com/nd-02110114/babel-plugin-object-to-json-parse/issues/12).\n\n## Development\n\nAny contributions are welcomed from everyone!!\n\n### Setup\n\n```sh\n$ git clone git@github.com:nissy-dev/babel-plugin-object-to-json-parse.git\n$ cd babel-plugin-object-to-json-parse\n$ yarn install\n```\n\n### Tips\n\n```sh\n// build\n$ yarn build\n\n// test\n$ yarn test\n```\n","funding_links":[],"categories":["Plugins"],"sub_categories":["Optimization"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnissy-dev%2Fbabel-plugin-object-to-json-parse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnissy-dev%2Fbabel-plugin-object-to-json-parse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnissy-dev%2Fbabel-plugin-object-to-json-parse/lists"}