A lightweight utility that converts Lombok's default toString() output format to standard JSON format.
Try the interactive converter at shuvojit.dev/lomboktojson:
Install the command-line interface tool:
go install github.com/sarkarshuvojit/lomboktojson/cmd/l2j@latestl2j "github.com/sarkarshuvojit/lomboktojson/pkg"
// Convert a Lombok toString string to JSON
lombokStr := "Customer(name=Raju,[email protected],age=15)"
jsonStr, err := l2j.LombokToJson(lombokStr)
// Result: {"name":"Raju","email":"[email protected]","age":15}The CLI tool offers three ways to provide input:
Simply run the tool without any arguments and paste or type your Lombok output. Press Ctrl+D when finished.
l2j > $(dirseq)-customer-data.json
# Paste your Lombok output and press Ctrl+D
# Creates: 1-customer-data.json with the JSON resultUse the -i flag to specify an input file:
l2j -i lombok-output.log > $(dirseq)-parsed-output.json
# Creates: 1-parsed-output.json with the JSON resultPipe content directly into the tool:
cat lombok-output.log | l2j > $(dirseq)-customer-records.json
# Creates: 1-customer-records.json with the JSON result$ cat lombokobjects.txt | xargs -L1 echo | l2j |sed 's/}/}\n/g' > $(dirseq)-jsonobjects.txt
# Reads line by line from a file containing lombok object in each line creating another file with same number of lines containing the json equivalent.# Extract logs containing Customer objects
grep "Customer(" application.log > lombok-logs.txt
# Convert to JSON and save to sequentially named file
cat lombok-logs.txt | l2j > $(dirseq)-converted-customers.json
# Creates: 1-converted-customers.json
# Process another batch
grep "Order(" application.log | l2j > $(dirseq)-converted-orders.json
# Creates: 2-converted-orders.jsonNote: The examples use dirseq to generate sequential filenames - a helpful utility for organizing outputs chronologically.
When using Lombok's @ToString or @Data annotations in Java classes, log output is generated in Lombok's specific format:
Customer(name=Raju,[email protected],age=15)
This format isn't easily parseable by standard tools that expect JSON:
{ "name": "Raju", "email": "[email protected]", "age": 15 }LombokToJson bridges this gap by providing a simple conversion utility.
- Convert Lombok's toString format to standard JSON
- Simple API for integration into existing projects
- No external dependencies
- High performance parsing
- Supports nested objects and collections
# Run tests
go test
# Run tests with verbose output
go test -v ./...Prerequisites: Install air
# Run tests automatically on file changes
air# Run tests
make test
# Run tests with verbose output
make testvThis project is licensed under the MIT License - see the LICENSE file for details.