# js-properties-to-json

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

Latest version **0.1.1** (published 2026-03-24) · MIT License license · 0 weekly downloads

## Install

```sh
npm install js-properties-to-json
pnpm add js-properties-to-json
yarn add js-properties-to-json
bun add js-properties-to-json
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2026-03-24 |
| First published | 2022-04-02 |
| Weekly downloads | 0 |
| License | MIT License |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 13.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 1 |
| Author | Himanshu Patil |
| Maintainers | mehimanshupatil |
| Keywords | java, properties, json, conversion |

## Links

- npm: https://www.npmjs.com/package/js-properties-to-json
- Repository: https://github.com/mehimanshupatil/propertiesToJSON
- Homepage: https://mehimanshupatil.github.io/propertiesToJSON/
- Issues: https://github.com/mehimanshupatil/propertiesToJSON/issues
- npm.io page: https://npm.io/package/js-properties-to-json

## Dependencies (1)

- [es-toolkit](https://npm.io/package/es-toolkit.md) ^1.45.1

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.1.1 (latest) — 2026-03-24
- 0.1.0 — 2023-05-16
- 0.0.6 — 2022-09-07
- 0.0.5 — 2022-08-31
- 0.0.4 — 2022-07-18
- 0.0.3 — 2022-07-18
- 0.0.2 — 2022-07-18
- 0.0.1 — 2022-04-02

## README

Convert Java `.properties` files to JSON (using JavaScript/TypeScript).

Supports nested objects, arrays, Unicode escape sequences, and type coercion.

## Install

```sh
# pnpm
pnpm add js-properties-to-json

# npm
npm i js-properties-to-json
```

## Usage

```ts
import propertiesToJSON from 'js-properties-to-json';
// or CommonJS:
// const propertiesToJSON = require('js-properties-to-json');

const result = propertiesToJSON(`
# comment
server.host=localhost
server.port=8080
`);
// { 'server.host': 'localhost', 'server.port': '8080' }
```

### Read a local file in Node.js

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

const data = fs.readFileSync('app.properties', 'utf-8');
console.log(propertiesToJSON(data, { convertToJsonTree: true, parseNumber: true }));
```

### Read a remote file in the browser

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

const text = await fetch('/app.properties').then((r) => r.text());
console.log(propertiesToJSON(text));
```

## Options

```ts
import propertiesToJSON, { type Options } from 'js-properties-to-json';
```

| Option                      | Default | Description                                                                                  |
| :-------------------------: | :-----: | :------------------------------------------------------------------------------------------: |
| `jsonAsString`              | `false` | Return the result as a JSON string instead of an object                                      |
| `convertToJsonTree`         | `false` | Convert dotted keys into nested objects — e.g. `a.b=c` → `{ a: { b: "c" } }`               |
| `parseNumber`               | `false` | Coerce numeric strings to numbers — e.g. `port=8080` → `{ port: 8080 }`                     |
| `parseBooleanNullUndefined` | `false` | Coerce `"true"`, `"false"`, `"null"`, `"undefined"` to their JS equivalents (case-sensitive) |

## Examples

| Properties         | JSON                               |
| ------------------ | ---------------------------------- |
| `a=b`              | `{ "a": "b" }`                     |
| `a:b`              | `{ "a": "b" }`                     |
| `a = b`            | `{ "a": "b" }`                     |
| `a[0]=x`           | `{ "a": ["x"] }`                   |
| `a[1][1]=b`        | `{ "a": [null, [null, "b"]] }`     |
| `a.b.c=d`          | `{ "a": { "b": { "c": "d" } } }` (requires `convertToJsonTree`) |
| `k=\u00e9`         | `{ "k": "é" }`                     |
| `k=hello\tworld`   | `{ "k": "hello\tworld" }`          |

## Supported escape sequences

| Sequence      | Result                  |
| ------------- | ----------------------- |
| `\uXXXX`      | Unicode character (hex) |
| `\t`          | Tab                     |
| `\n`          | Newline                 |
| `\r`          | Carriage return         |
| `\f`          | Form feed               |
| `\\`          | Literal backslash       |
| `\=`, `\:`    | Literal `=` or `:` in a key |

## Limitations

- Whitespace-only key separators (e.g. `key value`) are not supported — use `=` or `:`.
- Inline comments (e.g. `key=value # comment`) are not supported; the `# comment` becomes part of the value.
- `parseBooleanNullUndefined` is case-sensitive: `"True"` stays as a string.

## Online converter

[https://mehimanshupatil.github.io/propertiesToJSON/](https://mehimanshupatil.github.io/propertiesToJSON/)

## Inspiration

- [ryanpcmcquen/propertiesToJSON](https://github.com/ryanpcmcquen/propertiesToJSON)
- [jeanpaulattard/json-to-properties](https://github.com/jeanpaulattard/json-to-properties)

---
_Source: https://npm.io/package/js-properties-to-json · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
