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

json-to-properties

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-to-properties

A standalone utility to transform language files in JSON format into .properties files, and languages files in .properties format into JSON format.

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
700
increased by7.03%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 31 Jan 2018

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