{"id":17350594,"url":"https://github.com/nikhilunni511/jsonash","last_synced_at":"2026-06-20T04:31:23.974Z","repository":{"id":57285654,"uuid":"412870805","full_name":"nikhilunni511/jsonash","owner":"nikhilunni511","description":"Utility functions for JSON objects","archived":false,"fork":false,"pushed_at":"2021-10-04T18:54:41.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-17T04:14:01.177Z","etag":null,"topics":["camelcase","json","object-sort","object-validator","pascalcase","snakecase","sort","validator"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/jsonash","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/nikhilunni511.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":"2021-10-02T17:48:54.000Z","updated_at":"2021-10-06T00:16:58.000Z","dependencies_parsed_at":"2022-09-08T21:42:50.822Z","dependency_job_id":null,"html_url":"https://github.com/nikhilunni511/jsonash","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nikhilunni511/jsonash","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilunni511%2Fjsonash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilunni511%2Fjsonash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilunni511%2Fjsonash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilunni511%2Fjsonash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikhilunni511","download_url":"https://codeload.github.com/nikhilunni511/jsonash/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikhilunni511%2Fjsonash/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34557551,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-20T02:00:06.407Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["camelcase","json","object-sort","object-validator","pascalcase","snakecase","sort","validator"],"created_at":"2024-10-15T17:07:31.762Z","updated_at":"2026-06-20T04:31:23.958Z","avatar_url":"https://github.com/nikhilunni511.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jsonash\n\nUtility functions for JSON objects\n\n## Installation\n\nTo install module:\n\n```\n$ npm install --save jsonash\n```\n\n## Contents\n\n1. [Sort array of objects](#1-sort-object-based-on-key)\n2. [To convert all the keys to camelCase](#2-to-convert-all-the-keys-to-camelcase)\n3. [To convert all the keys to snake_Case](#3-to-convert-all-the-keys-to-snake_case)\n4. [To convert all the keys to PascalCase](#4-to-convert-all-the-keys-to-pascalcase)\n5. [Format key with custom function](#5-format-key-with-custom-function)\n6. [To replace a key from the object](#6-to-replace-a-key-from-the-object)\n7. [To validate a JSON object](#7-to-validate-a-json-object)\n\n## Usage/Examples\n\nImport jsonash into your file like below:\n\n```javascript\nconst jsonash = require(\"jsonash\");\n```\n\n### 1. Sort object based on key\n\n```javascript\nconst obj = [\n  { a: 1, b: { c: 7 } },\n  { a: 5, b: { c: 4 } },\n  { a: 8, b: { c: 5 } },\n];\n/* The object get sorted based on the key obj-\u003eb\u003ec */\nconst options = { desc: true, path: \"b.c\" };\njsonash.sort(obj, options);\n\n/*\nOutput: \n[ { a: 1, b: { c: 7 } }, { a: 8, b: { c: 5 } }, { a: 5, b: { c: 4 } } ]\n*/\n```\n\nThe parameter path is required that defines the depth of the object to be sorted.\n\n### 2. To convert all the keys to camelCase\n\n```javascript\nconst obj = {\n  first_name: \"John\",\n  last_name: \"John\",\n  phone_number: 999555,\n};\njsonash.toCamelCase(obj);\n\n/*\nOutput: \n{ firstName: 'John', lastName: 'John', phoneNumber: 999555 }\n*/\n\n/* You can pass array of objects to the method */\n\nconst objArray = [\n  { first_name: \"John\", last_name: \"John\", phone_number: 999555 },\n  { first_name: \"Mike\", last_name: \"Mike\", phone_number: 123 },\n  { first_name: \"Michael\", last_name: \"Michael\", phone_number: 456 },\n];\njsonash.toCamelCase(objArray);\n\n/*\nOutput:\n[\n  { firstName: 'John', lastName: 'John', phoneNumber: 999555 },\n  { firstName: 'Mike', lastName: 'Mike', phoneNumber: 123 },\n  { firstName: 'Michael', lastName: 'Michael', phoneNumber: 456 }\n]\n*/\n```\n\n### 3. To convert all the keys to snake_Case\n\n```javascript\nconst obj = { firstName: \"John\", lastName: \"John\", phoneNumber: 999555 };\njsonash.toSnakeCase(obj);\n\n/*\nOutput: \n{ first_name: 'John', last_name: 'John', phone_number: 999555 }\n*/\n\n/* You can pass array of objects to the method */\n\nconst objArray = [\n  { firstName: \"John\", lastName: \"John\", phoneNumber: 999555 },\n  { firstName: \"Mike\", lastName: \"Mike\", phoneNumber: 123 },\n  { firstName: \"Michael\", lastName: \"Michael\", phoneNumber: 456 },\n];\njsonash.toCamelCase(objArray);\n\n/*\nOutput:\n[\n  { first_name: 'John', last_name: 'John', phone_number: 999555 },\n  { first_name: 'Mike', last_name: 'Mike', phone_number: 123 },\n  { first_name: 'Michael', last_name: 'Michael', phone_number: 456 }\n]\n*/\n```\n\n### 4. To convert all the keys to PascalCase\n\n```javascript\nconst obj = {\n  first_name: \"John\",\n  last_name: \"John\",\n  phone_number: 999555,\n};\njsonash.toCamelCase(obj);\n\n/*\nOutput: \n{ FirstName: 'John', LastName: 'John', PhoneNumber: 999555 }\n*/\n\n/* You can pass array of objects to the method */\n\nconst objArray = [\n  { first_name: \"John\", last_name: \"John\", phone_number: 999555 },\n  { first_name: \"Mike\", last_name: \"Mike\", phone_number: 123 },\n  { first_name: \"Michael\", last_name: \"Michael\", phone_number: 456 },\n];\njsonash.toCamelCase(objArray);\n\n/*\nOutput:\n[\n  { FirstName: 'John', LastName: 'John', PhoneNumber: 999555 },\n  { FirstName: 'Mike', LastName: 'Mike', PhoneNumber: 123 },\n  { FirstName: 'Michael', LastName: 'Michael', PhoneNumber: 456 }\n]\n*/\n```\n\n### 5. Format key with custom function\n\n```javascript\nconst obj = {\n  first_name: \"John\",\n  last_name: \"John\",\n  phone_number: 999555,\n};\n\nfunction customMethod(str) {\n  return str + \"TEST\";\n}\n\n/*The second argument must be a function and it takes a string as input and return string as output\n */\njsonash.formatKeys(obj, customMethod);\n\n/*\nOutput: \n{ first_nameTEST: \"John\", last_nameTEST: \"John\", phone_numberTEST: 999555 },\n*/\n\n/* You can pass array of objects to the method */\n\nconst objArray = [\n  { first_name: \"John\", last_name: \"John\", phone_number: 999555 },\n  { first_name: \"Mike\", last_name: \"Mike\", phone_number: 123 },\n  { first_name: \"Michael\", last_name: \"Michael\", phone_number: 456 },\n  { user: { first_name: \"Alice\", last_name: \"Alice\", phone_number: 789 } },\n];\njsonash.formatKeys(objArray, customMethod);\n\n/*\nOutput:\n[\n    { first_nameTEST: \"John\", last_nameTEST: \"John\", phone_numberTEST: 999555 },\n    { first_nameTEST: 'Mike', last_nameTEST: 'Mike', phone_numberTEST: 123 },\n    { first_nameTEST: 'Michael', last_nameTEST: 'Michael', phone_numberTEST: 456 },\n    { userTEST: { first_nameTEST: 'Alice', last_nameTEST: 'Alice', phone_numberTEST: 789 } }\n];\n*/\n```\n\n### 6. To replace a key from the object\n\n```javascript\nconst obj = {\n  first_name: \"John\",\n  last_name: \"John\",\n  phone_number: 999555,\n};\njsonash.replacetKeys(obj, \"phone_number\", \"mobile_number\");\n\n/*\nOutput: \n{ first_name: 'John', last_name: 'John', mobile_number: 999555 }\n*/\n\n/* You can pass array of objects or and nested objects to the method */\n\nconst objArray = [\n  { first_name: \"John\", last_name: \"John\", phone_number: 999555 },\n  { first_name: \"Mike\", last_name: \"Mike\", phone_number: 123 },\n  { first_name: \"Michael\", last_name: \"Michael\", phone_number: 456 },\n  { user: { first_name: \"Alice\", last_name: \"Alice\", phone_number: 789 } },\n];\njsonash.toCamelCase(objArray);\n\n/*\nOutput:\n[\n  { first_name: 'John', last_name: 'John', mobile_number: 999555 },\n  { first_name: 'Mike', last_name: 'Mike', mobile_number: 123 },\n  { first_name: 'Michael', last_name: 'Michael', mobile_number: 456 },\n  {\n    user: { first_name: 'Alice', last_name: 'Alice', mobile_number: 789 }\n  }\n]\n*/\n```\n\n### 7. To validate a JSON object\n\n```javascript\nconst obj = { last_name: '12345', phone_number: 999555, is_admin: 'true' };\nconst options = {\n    rules: {\n        first_name: {\n            type: \"string\",\n            max: 5,\n            min: 2,\n            required: true\n        },\n        last_name: {\n            type: \"string\",\n            max: 4,\n            min: 3\n        },\n        is_admin: {\n            type: 'boolean'\n        }\n    }\n}\nIf the JSON is valid return true or get a response object with error messages corresponding to each field.\n/*\nOutput:\n{\n  first_name: [ 'required' ],\n  last_name: [ 'last_name must contain a maximum of 4 characters.' ],\n  is_admin: [ 'is_admin must be of type boolean' ],\n  error: true\n}\n*/\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikhilunni511%2Fjsonash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikhilunni511%2Fjsonash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikhilunni511%2Fjsonash/lists"}