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

js-properties-to-json

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

js-properties-to-json

Convert a Java properties file to JSON (with JavaScript).

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
409
increased by54.34%
Maintainers
1
Weekly downloads
 
Created
Source

Convert Java .properties files to JSON (using JavaScript).

supports array creation.

The function propertiesToJSON takes a string and returns a JavaScript object.

use

 propertiesToJSON(data, {
                jsonAsString: false,
                convertToJsonTree : false,
                parseNumber:false,
                parseBooleanNullUndefined:false,
            });

Read a local file in node:

const fs = require('fs');
const path = require('path');
const filePath = path.join(__dirname, 'sample.properties');
const propertiesToJSON = require('properties-to-json');;

fs.readFile(filePath, { encoding: 'utf-8' }, (err, data) => {
    if (!err) {
        console.log(propertiesToJSON(data));
    }
});

Read a remote file in the browser:

import propertiesToJSON from 'js-properties-to-json';

const propsFile = new Request('<link-to-properties-file>');

const props = fetch(propsFile)
    .then((response) => {
        return response.text();
    })
    .then((text) => {
        const propsText = propertiesToJSON(text);
        console.log(propsText);
        return propsText;
    });

Available options

OptionDefault valueDescription
jsonAsStringfalsereturn json as a string
convertToJsonTreefalseconvert properties to json tree eg a.b=c to { "a.b": c } if false or { "a": {"b": c} }
parseNumberfalseparse value to number e.g - a=1 to { a: "1" } or { a: 1 }
parseBooleanNullUndefinedfalseparse string value of null, true, false, undefined

Examples

PropertiesJSON
a=b{ "a": "b" }
a[1][1]=b{ "a": [ null, [ null, "b" ] ] }

How do I get it?

  1. npm i js-properties-to-json

online converter

link

inspiration

https://github.com/ryanpcmcquen/propertiesToJSON https://github.com/jeanpaulattard/json-to-properties

Keywords

FAQs

Package last updated on 16 May 2023

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