GithubHelp home page GithubHelp logo

jungsoo827 / json-to-properties Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jeanpaulattard/json-to-properties

0.0 1.0 1.0 32 KB

A util to convert .json format files into .properties format, and vice versa

License: MIT License

JavaScript 100.00%

json-to-properties's Introduction

json-to-properties

npm version

A util to convert files having a .json format into .properties format, and vice versa.

Installation

npm install json-to-properties -g

Usage

Running json-to-properties will convert any .json files that are found in the current directory, into to .properties files.

Example

{
    "KEY1": {
        "KEY2": "Hello"
    },
    "KEY3":"World"
}

result in a file containing

KEY1.KEY2=Hello
KEY3=World

Options

Various options are supported, including

-c, --config

Running the util with -c expects a config file in .json format containing two attributes: src and dist, where

  • src points to the directory containing the files to process and
  • dist points to the directory where the output files will be written

Example config.json

{
    src: "c:\json\myfiles",
    dist: "c:\properties\myconvertedfiles"
}

and run with

json-to-properties -c config.json

-r, --reverse

Performs the reversal process, converting .properties files into .json files.

Example

KEY1.KEY2=Hello
KEY3=World

result into a file containing

{
    "KEY1": {
        "KEY2": "Hello"
    },
    "KEY3":"World"
}

-s, --spaces

Accepts a number value identifying the number of spaces used within the output .json file. This is used in relation with -r, --reverse

Run using

json-to-properties -r -s 4

will use 4 spaces for each indented hierarchy.

-m, --merge

Running the util with the -m, --merge option bundles the generated .properties files into one file of a given name, or bundle.properties if none is specified. The content of the bundled file are prefixed with the name of the original file.

Example

json-to-properties -m bundles the content in a file named bundle.properties

json-to-properties -m mynewbundle.properties bundles the content in a file named mynewbundle.properties

Having two files en.json and it.json both containing the json content below

{
    "KEY1" : "Hello Sir",
    "KEY2" : "How is your day?"
}

will result in a bundle file bundle.properties having the below content.

EN.KEY1=Hello Sir
EN.KEY2=How is your day?
IT.KEY1=Hello Sir
IT.KEY2=How is your day?

Note that the standard behavior is preserved, thus two properties files en.properties and it.properties are also created.

Use of merge in conjunction with -r, --reverse option

The merge process can also be combined with the -r, -reverse flag, where the specified file (or bundle.properties if none is specified) is expanded into separate json files whose name is equivalent to the first part of a key.

Example

json-to-properties -r -m or json-to-properties -rm

Having a bundle file bundle.properties with the below content

EN.KEY1=Hello Sir
EN.KEY2=How is your day?
IT.KEY1=Salve signore
IT.KEY2=Com'è la tua giornata?

will result in two files, en_rm.json and it_rm.json, having the below content respectively.

{
    "KEY1": "Hello Sir",
    "KEY2": "How is your day?"
}

and

{
    "KEY1": "Salve signore",
    "KEY2": "Com'è la tua giornata?"
}

Note that the generated json files are suffixed with _rm not to override other .json files having the same name (in this case, en.json and it.json) that could be a result of the standard behavior of the reverse process.

Try It

The sample folder contains both .json and .properties files to download and test on.

json-to-properties's People

Contributors

jeanpaulattard avatar jungsoo827 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.