Skip to content

A tiny utility module for converting json objects between various coding styles

License

Notifications You must be signed in to change notification settings

alexnm/json-style-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json-style-converter

A tiny utility module for converting json objects between various coding styles. This is especially useful in projects which are written in multiple programming languages and use REST Apis to comunicate - for example backend in Ruby, frontend in JavaScript.

Build Status

Install via npm

npm i json-style-converter

Example usage

const converter = require( "json-style-converter" );

converter.snakeToCamelCase( {
    snake_case: "A simple test",
    camelCase: 42,
    array: [ {
        it_works: true
    }, {
        it_works: null
    } ]
} );

/* returns
{
    snakeCase: "A simple test",
    camelCase: 42,
    array: [ {
        itWorks: true
    }, {
        itWorks: null
    } ]
}*/

For using the es5 browser compatible Build

const converter = require( "json-style-converter/es5" );

or

import converter from "json-style-converter/es5";

API

converter.snakeToCamelCase

Transforms all the keys of object recursively from snake_case to camelCase.

converter.camelToSnakeCase

Transforms all the keys of object recursively from camelCase to snake_case.

-- Ping me on twitter, i'd be more than happy to hear your thoughts!

Alex M

About

A tiny utility module for converting json objects between various coding styles

Resources

License

Stars

Watchers

Forks

Packages

No packages published