Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-case-convertor

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-case-convertor

JsonCaseConvertor can handle literraly any json object for case convertion. ## Features

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

JsonCaseConvertor

Convert any json object key name and values case

JsonCaseConvertor can handle literraly any json object for case convertion.

Features

  • Supported cases: Pascal, Camel, Snake, Kebab, Upper, Lower, Constant, Dot, Path, Sentence, Title
  • Support array objects
  • Support objects within objects
  • Support object values case convertion
  • Support object keys case convertion
  • One line code implementation

Installation

npm install json-case-convertor

Usage

Import:

const jcc = require('json-case-convertor')

Convert only object KEYS Names:

const jsonData = { 
	"firstName": "John", 
	"lastName": "Wick", 
	"car": "Ford Mustang",
	"car2": null,
	"prize": 2000,
	"other" : ['sample1', 'sample2'],
	"other2" : {
		"location": "America",
		"longitude1": 23.4,
		"latitude1" : 23.11
	}
}
jcc.snakeCaseKeys(jsonData); //Convert all the keys of object to snake case

Output:

{
  first_name: 'John',
  last_name: 'Wick',
  car: 'Ford Mustang',
  car_2: null,
  prize: 2000,
  other: [ 'sample1', 'sample2' ],
  other_2: { location: 'America', longitude_1: 23.4, latitude_1: 23.11 }
}

Convert only object values:

jcc.snakeCaseValues(jsonData) //Convert all the values of object to snake case

Output:

{
  firstName: 'john',
  lastName: 'wick',
  car: 'ford_mustang',
  car2: null,
  prize: 2000,
  other: [ 'sample1', 'sample2' ],
  other2: { location: 'america', longitude1: 23.4, latitude1: 23.11 }
}

Convert only object keys and values:

jcc.snakeCaseAll(jsonData) //Convert all the values and keys of object to snake case

Output:

{
  first_name: 'john',
  last_name: 'wick',
  car: 'ford_mustang',
  car_2: null,
  prize: 2000,
  other: [ 'sample1', 'sample2' ],
  other_2: { location: 'america', longitude_1: 23.4, latitude_1: 23.11 }
}

Functions

const jcc = require('json-case-convertor')

jcc.pascalCaseKeys(jsonData)

jcc.camelCaseKeys(jsonData)

jcc.snakeCaseKeys(jsonData)

jcc.kebabCaseKeys(jsonData)

jcc.upperCaseKeys(jsonData)

jcc.lowerCaseKeys(jsonData)

jcc.constantCaseKeys(jsonData)

jcc.dotCaseKeys(jsonData)

jcc.pathCaseKeys(jsonData)

jcc.sentenceCaseKeys(jsonData)

jcc.titleCaseKeys(jsonData)

//-------------------------

jcc.pascalCaseAll(jsonData)

jcc.camelCaseAll(jsonData)

jcc.snakeCaseAll(jsonData)

jcc.kebabCaseAll(jsonData)

jcc.upperCaseAll(jsonData)

jcc.lowerCaseAll(jsonData)

jcc.constantCaseAll(jsonData)

jcc.dotCaseAll(jsonData)

jcc.pathCaseAll(jsonData)

jcc.sentenceCaseAll(jsonData)

jcc.titleCaseAll(jsonData)

//----------------------------
jcc.pascalCaseValues(jsonData)

jcc.camelCaseValues(jsonData)

jcc.snakeCaseValues(jsonData)

jcc.kebabCaseValues(jsonData)

jcc.upperCaseValues(jsonData)

jcc.lowerCaseValues(jsonData)

jcc.constantCaseValues(jsonData)

jcc.dotCaseValues(jsonData)

jcc.pathCaseValues(jsonData)

jcc.sentenceCaseValues(jsonData)

jcc.titleCaseValues(jsonData)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

ISC

FAQs

Package last updated on 22 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc