1.0.3 • Published 10 months ago

json-case-convertor-ts v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

JsonCaseConvertorTS

Convert any json object key name and values case

It's TS fork of original lib JsonCaseConvertor https://github.com/MIRTAHAALI/json-case-convertor

JsonCaseConvertorTS 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-ts

Usage

Import:

import { snakeCaseKeys, snakeCaseValues } from 'json-case-converter-ts';

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
	}
}
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:

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

Output:

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

Convert only object keys and values:

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: [ 'sample_1', 'sample_2' ],
  other_2: { location: 'america', longitude_1: 23.4, latitude_1: 23.11 }
}

License

ISC

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago