A Java application that converts nested JSON structures into a flat representation with detailed structure markers.
Process existing JSONL (JSON Lines) files on your filesystem.
Connect to Fabricate API to generate synthetic data, then automatically flatten it.
The tool converts JSON data into a structured format with the following markers:
- Objects: Start with
"value": "Structure"
and end with"value": "EndStructure"
- Arrays: Start with the array length as value and end with
"value": "EndArray"
- Primitives: Direct key-value pairs
Input JSONL:
{
"name": "John",
"location": { "city": "New York" },
"nicknames": ["Jon-boy", "Johnny"]
}
Output:
[
{
"fields": [
{ "key": "name", "value": "John" },
{ "key": "location", "value": "Structure" },
{ "key": "location.city", "value": "New York" },
{ "key": "location.", "value": "EndStructure" },
{ "key": "nicknames", "value": "2" },
{ "key": "nicknames[0]", "value": "Jon-boy" },
{ "key": "nicknames[1]", "value": "Johnny" },
{ "key": "nicknames.", "value": "EndArray" }
]
}
]
- Java 17 or later
- Maven 3.6 or later
mvn clean compile
Create a JAR file with all dependencies:
mvn clean package
mvn test
After building, you can also run the application directly from the JAR file:
java -jar target/json-flattener-1.0.0.jar path/to/file.jsonl
Transform a local file:
mvn exec:java -Dexec.mainClass="ai.tonic.fabricate.tools.App" -Dexec.args="path/to/file.jsonl"
# Or using the shorter command:
mvn exec:java -Dexec.args="path/to/file.jsonl"
Generate data with Fabricate:
# Set up .env file first (see Configuration section)
mvn exec:java -Pfabricate
Process existing JSONL files on your filesystem:
mvn exec:java -Dexec.mainClass="ai.tonic.fabricate.tools.App" -Dexec.args="path/to/your/file.jsonl"
# Or using the shorter command:
mvn exec:java -Dexec.args="path/to/your/file.jsonl"
Example:
mvn exec:java -Dexec.args="/Users/john/data/customers.jsonl"
This mode requires:
- ✅ A valid JSONL file path
- ❌ No Fabricate API configuration needed
Generate synthetic data via Fabricate API and automatically flatten it:
# Uses entity from .env file
mvn exec:java -Pfabricate
This mode requires:
- ✅ Fabricate API configuration (see Configuration section below)
- ✅ Valid API key and workspace access
- ❌ No local files needed
The application supports loading configuration from environment variables or a .env
file for Fabricate API integration.
Create a .env
file in the project root or set these environment variables:
# Required
FABRICATE_API_KEY=sk-your-api-key-here
WORKSPACE=your-workspace-name
DATABASE=your-database-name
ENTITY=users
# Optional
FABRICATE_URI_BASE=http://localhost:3000 # defaults to https://fabricate.tonic.ai
-
Copy the example configuration:
cp env.example .env
-
Edit
.env
with your actual values:FABRICATE_API_KEY=sk-abc123xyz... WORKSPACE=my-workspace DATABASE=my-database ENTITY=users
-
Run the Fabricate integration:
mvn exec:java -Pfabricate
<root>/
├── src/main/java/ai/tonic/fabricate/tools/
│ ├── App.java # Main application logic (Mode 1)
│ ├── FabricateExample.java # Fabricate integration (Mode 2)
│ ├── JsonFlattener.java # Core flattening logic
│ ├── FabricateClient.java # Fabricate API client
│ └── EnvConfig.java # Environment configuration
├── data/
│ └── example.jsonl # Sample input file
├── target/ # Maven build directory
├── pom.xml # Maven project configuration
└── README.md # This file
- Jackson Databind: For JSON parsing and processing
- OkHttp: HTTP client for Fabricate API calls
- Dotenv Java: Environment variable loading from .env files
- JUnit: For testing (test framework)
- Guava: Utility libraries
The application expects JSONL (JSON Lines) format where each line contains a valid JSON object:
{"field1": "value1", "nested": {"field2": "value2"}}
{"field1": "value3", "array": ["item1", "item2"]}
App.java
: Mode 1 entry point (local file processing)FabricateExample.java
: Mode 2 entry point (Fabricate API integration)JsonFlattener.java
: Core flattening logic (used by both modes)FabricateClient.java
: Fabricate API communication (Mode 2 only)EnvConfig.java
: Environment configuration (Mode 2 only)
processJsonlFile()
: Reads and processes JSONL filesflattenJsonNode()
: Converts JSON nodes to flattened structureflattenNode()
: Recursively processes nested objects and arrays