{"id":16427068,"url":"https://github.com/donavon/json_","last_synced_at":"2025-03-21T04:30:41.406Z","repository":{"id":11122034,"uuid":"13481736","full_name":"donavon/json_","owner":"donavon","description":"Converts camelCase JavaScript objects to JSON snake_case and vise versa.","archived":false,"fork":false,"pushed_at":"2022-03-26T13:26:19.000Z","size":442,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-17T20:44:50.200Z","etag":null,"topics":["fetch","javascript","json","json-snake-case","rest"],"latest_commit_sha":null,"homepage":null,"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/donavon.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":"2013-10-10T20:09:23.000Z","updated_at":"2023-02-02T01:43:43.000Z","dependencies_parsed_at":"2022-09-10T04:05:01.184Z","dependency_job_id":null,"html_url":"https://github.com/donavon/json_","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/donavon%2Fjson_","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donavon%2Fjson_/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donavon%2Fjson_/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donavon%2Fjson_/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/donavon","download_url":"https://codeload.github.com/donavon/json_/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244738159,"owners_count":20501787,"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":["fetch","javascript","json","json-snake-case","rest"],"created_at":"2024-10-11T08:11:27.900Z","updated_at":"2025-03-21T04:30:41.094Z","avatar_url":"https://github.com/donavon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json\\_\n\n[![Build Status](https://travis-ci.org/donavon/json_.svg?branch=master)](https://travis-ci.org/donavon/json_) [![npm version](https://img.shields.io/npm/v/json_.svg)](https://www.npmjs.com/package/json_)\n\nConverts camelCase JavaScript objects to JSON snake_case and vise versa. This is a direct replacement for the built-in JSON object. In fact, this simply wraps the built-in JSON object. Very handy when your back_end APIs are not build using Node.js.\nIt also supports converting a `fetch` response stream into a camelCased object.\n\n\u003e NOTE: New version 3.0 completely re-written in TypeScript, so it's fully typed.\n\n## First, get the package\n\nInstall json\\_ and include it in your build.\n\n```bash\nnpm install json_ --save\n```\n\nThen import it like this.\n\n```js\nimport JSON_ from 'json_';\n```\n\n## Example\n\n```js\nconst example = {\n  firstName: 'John',\n  lastName: 'Doe',\n  isbn10: '1234567890',\n};\n\nconsole.log(JSON_.stringify(example));\n// {\"first_name\":\"John\",\"last_name\":\"Doe\", \"isbn_10\": \"1234567890\"}\n```\n\nAnd vise versa.\n\n```js\nimport JSON_ from 'json_';\nconst str = '{\"ultimate_answer\": 42}';\n\nconsole.log(JSON_.parse(str));\n// {ultimateAnswer: 42}\n```\n\n## Using with `fetch`\n\nYou can use `json_` directly with the JavaScript `fetch` API to convert\nthe `Response` into an `Object` with snakeCase.\n\nLet's say you have a function that returns snake_case weather data, something like this.\n\n```js\nconst fetchWeather = async zip =\u003e {\n  const response = fetch(`${weatherUrl}?zip=${zip}`);\n  const json = await response.json();\n  return json;\n};\n\nconst data = await fetchWeather('10285');\nconsole.log(data);\n// {current_temp: 85, reporting_station: 'New York, NY'}\n```\n\nYou can easily convert the resolved object to camelCase by replacing the call to `Response.json()`\nto a call to `JSON_.parse(Response)`, like this.\n\n```diff\n- const json = await response.json();\n+ const json = await JSON_.parse(response);\n```\n\nThe resulting code looks like this\n\n```js\nimport JSON_ from 'json_';\n\nconst fetchWeather = async zip =\u003e {\n  const response = fetch(`${weatherUrl}?zip=${zip}`);\n  const json = await JSON_.parse(response);\n  return json;\n};\n\nconst data = await fetchWeather('10285');\nconsole.log(data);\n// {currentTemp: 85, reportingStation: 'New York, NY'}\n```\n\n## Tests!\n\n100% unit test coverage. To run the unit tests and get a coverage report:\n\n```\nnpm test coverage\n```\n\n## License\n\nCopyright Donavon West. Released under MIT license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonavon%2Fjson_","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdonavon%2Fjson_","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonavon%2Fjson_/lists"}