Skip to content

TatChu/json-case-sensitive-resolver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JsonHelper

Easy to convert JSON string to object with various case-sensitive resolver

Usage

Prerequisite

 npm i --save json-case-sensitive-resolver
  • Parse a camelCase JSON to PascalCase object
import JsonHelper from 'json-case-sensitive-resolver'

let jsonString = '{"camelCaseToPascalCase": "thanks for reading me"}';
const parsedPascalCaseObj = JsonHelper.parseToPascalCase(jsonString); 
//>>> { CamelCaseToPascalCase: "thanks for reading me" }
  • Parse a PascalCase JSON to camelCase object
import JsonHelper from 'json-case-sensitive-resolver'

let jsonString = '{"PascalCaseToCamelCase": "thanks for reading me"}';
const parsedCamelCaseObj = JsonHelper.parseToCamelCase(jsonString); 
//>>> { pascalCaseToCamelCase: "thanks for reading me" }

Advanced options

  • parseFromKebapCase: parse snake_case to PascalCase|camelCase Example:

    import JsonHelper from 'json-case-sensitive-resolver'
    
    let jsonString = '{"this-is-kebap-case": "thanks for reading me"}';
    const parsedPascalCaseObj = JsonHelper.parseToPascalCase(jsonString, { parseFromKebapCase: true }); 
    //>>> { ThisIsKebapCase: "thanks for reading me" }
  • parseFromSnakeCase: parse kebap-case to PascalCase|camelCase Example:

    import JsonHelper from 'json-case-sensitive-resolver'
    
    let jsonString = '{"this_is_snake_case": "thanks for reading me"}';
    const parsedPascalCaseObj = JsonHelper.parseToCamelCase(jsonString, { parseFromSnakeCase: true }); 
    //>>> { thisIsSnakeCase: "thanks for reading me" }

And yes, you can completely combine two option together

import JsonHelper from 'json-case-sensitive-resolver'

let jsonString = '{"this_is_snake_case": "snake", "this-is-kebap-case": "kebap"}';
const obj = JsonHelper.parseToCamelCase(jsonString, { parseFromSnakeCase: true, parseFromKebapCase: true }); 
//>>> { thisIsSnakeCase: "snake", thisIsKebapCase: "kebap" }

About

JSON converter with case-sensitive resolver

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published