Skip to content

Commit 9352f85

Browse files
committed
Initial commit
0 parents  commit 9352f85

File tree

9 files changed

+547
-0
lines changed

9 files changed

+547
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

.github/workflows/release.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Build & Upload Release Binaries
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
include:
16+
- goos: linux
17+
goarch: amd64
18+
- goos: linux
19+
goarch: arm64
20+
- goos: darwin
21+
goarch: arm64
22+
steps:
23+
- name: Check out code
24+
uses: actions/checkout@v5
25+
26+
- name: Set up Go
27+
uses: actions/setup-go@v6
28+
with:
29+
go-version: '1.25.x'
30+
cache: true
31+
32+
- name: Verify module & run tests
33+
run: |
34+
go mod tidy
35+
go test ./... -race -cover
36+
37+
- name: Build ${{ matrix.goos }}/${{ matrix.goarch }}
38+
env:
39+
GOOS: ${{ matrix.goos }}
40+
GOARCH: ${{ matrix.goarch }}
41+
CGO_ENABLED: 0
42+
run: |
43+
mkdir -p dist
44+
BIN_NAME=json-to-properties
45+
OUT="dist/${BIN_NAME}_${GOOS}_${GOARCH}"
46+
# Build (strip symbols, reproducible-ish)
47+
go build -trimpath -ldflags="-s -w" -o "$OUT" ./...
48+
49+
- name: Upload assets to the release
50+
uses: softprops/action-gh-release@v2
51+
with:
52+
files: dist/*
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tests.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Go Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request: ~
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check out code
13+
uses: actions/checkout@v5
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v6
17+
with:
18+
go-version: '1.25.x'
19+
cache: true
20+
21+
- name: Verify module
22+
run: go mod tidy
23+
24+
- name: Run tests (verbose, race)
25+
run: go test ./... -v -race -coverprofile=coverage.out
26+
27+
- name: Upload coverage artifact
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: coverage
31+
path: coverage.out

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Binaries
2+
json-to-properties
3+
4+
# Test binaries
5+
*.test
6+
7+
# Output of `go build`, `go install`, `go run`
8+
*.exe
9+
*.exe~
10+
*.dll
11+
*.so
12+
*.dylib
13+
14+
# Go coverage tool
15+
*.out
16+
17+
# Logs
18+
*.log
19+
20+
# IDE/editor cruft
21+
.vscode/
22+
.idea/
23+
*.swp
24+
*.swo
25+
26+
# macOS
27+
.DS_Store

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Noël Hagestein
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# json-to-properties
2+
3+
A small CLI tool that converts JSON into Java `.properties` files.
4+
5+
Useful if you manage translations in JSON but need `.properties` files for Java’s `ResourceBundle` or Spring.
6+
7+
---
8+
9+
## Features
10+
11+
- Flattens nested JSON into dot-notation keys
12+
- Supports arrays (`arr.0`, `arr.1`, …)
13+
- Escapes keys and values for safe `.properties` syntax
14+
- Optional prefix for all keys
15+
- Optional sorted output for stable diffs
16+
- UTF-8 safe (no `\uXXXX` escaping by default)
17+
18+
---
19+
20+
## Installation
21+
22+
Download a binary from the [Releases](https://github.com/recoded-dev/json-to-properties/releases) page.
23+
24+
Or build from source:
25+
26+
```bash
27+
git clone https://github.com/recoded-dev/json-to-properties.git
28+
cd json-to-properties
29+
go build -o json-to-properties .
30+
````
31+
32+
---
33+
34+
## Usage
35+
36+
```bash
37+
./json-to-properties -in en.json -out messages_en.properties
38+
```
39+
40+
### Options
41+
42+
* `-in` : input JSON file (default: stdin)
43+
* `-out` : output `.properties` file (default: stdout)
44+
* `-prefix` : optional prefix for all keys (e.g. `app`)
45+
* `-sort` : sort keys alphabetically
46+
47+
### Example
48+
49+
`en.json`:
50+
51+
```json
52+
{
53+
"home": {
54+
"title": "Welcome",
55+
"cta": "Start"
56+
},
57+
"about": "About us"
58+
}
59+
```
60+
61+
Command:
62+
63+
```bash
64+
./json-to-properties -in en.json -out messages_en.properties -sort
65+
```
66+
67+
Output:
68+
69+
```
70+
about=About us
71+
home.cta=Start
72+
home.title=Welcome
73+
```
74+
75+
---
76+
77+
## Development
78+
79+
Run tests:
80+
81+
```bash
82+
go test
83+
```

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module json-to-properties
2+
3+
go 1.25.1

0 commit comments

Comments
 (0)