0.0
No commit activity in last 3 years
No release in over 3 years
Simple converted from JSON to Java properties
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

json2properties

Simple tool that converts JSON files to equivalent content in Java properties format. Nested structures are flattened to fit properties key-value format. Provides reverse operation as well.

Example

Source (JSON)

{
	"a": 1,
	"b": "two",
	"c": [1, 2, 3],
	"d": {
		"k": 123,
		"l": "asd",
		"m": {
			"types": "hash",
			"and": ["ar", "ra", "y"]
		}
	}
}

Destination (.properties)

a=1
b=two
c.0=1
c.1=2
c.2=3
d.k=123
d.l=asd
d.m.types=hash
d.m.and.0=ar
d.m.and.1=ra
d.m.and.2=y

Usage

Shell

$ gem install json2propeties
$ json2propeties input.json output.properties

# to perform reverse conversion:
$ propeties2json input.properties output.json

Code

# Assuming gem has been installed
require 'json2propeties'

converter = Json2properties.new

# Convert json to properties
converter.convert_file('/tmp/input.json', '/tmp/output.properties')

# Convert properties to json
converter.unconvert_file('/tmp/input.properties', '/tmp/output.json')

# Convert JSON string to flattened key-value Hash
json = JSON.generate({
	a: 1,
	h: {
		x: 1,
		y: 2
	},
	a: [4, 5, 6]
})
props = converter.json2kv(json)
# props == {
	"a" => 1,
	"h.x" => 1,
	"h.y" => 2,
	"a.0" => 4,
	"a.1" => 5,
	"a.2" => 6,
}

# reverse action
reverse_engineered_json = converter.kv2json(props)