Convert Properties to JSON
Max file size 100mb.
Properties vs JSON Format Comparison
| Aspect | Properties (Source Format) | JSON (Target Format) |
|---|---|---|
| Format Overview |
Properties
Java Properties File
Plain text configuration format using key=value pairs, fundamental to the Java platform. Powers Spring Boot configuration (application.properties), resource bundles for i18n, Maven/Gradle build settings, and JDBC parameters. Uses dotted notation for hierarchical namespaces. Key-Value Pairs Flat Structure |
JSON
JavaScript Object Notation
Lightweight data interchange format based on JavaScript object syntax. JSON supports nested objects, arrays, strings, numbers, booleans, and null values. It is the dominant format for web APIs, configuration files (package.json, tsconfig.json), and data storage across virtually all programming languages. Data Interchange Nested Structure |
| Technical Specifications |
Structure: Line-oriented key=value pairs
Encoding: ISO 8859-1 (Latin-1) / UTF-8 Format: java.util.Properties specification Compression: None Extensions: .properties |
Structure: Nested objects and arrays
Encoding: UTF-8 (required by RFC 8259) Format: RFC 8259 / ECMA-404 Compression: None (often gzipped in transit) Extensions: .json |
| Syntax Examples |
Flat properties with dotted namespaces: # Application Config app.name=OrderService app.version=3.2.1 app.features.caching=true app.features.metrics=true app.cors.origins=http://localhost,https://app.com |
Nested JSON with typed values: {
"app": {
"name": "OrderService",
"version": "3.2.1",
"features": {
"caching": true,
"metrics": true
},
"cors": {
"origins": ["http://localhost", "https://app.com"]
}
}
}
|
| Content Support |
|
|
| Advantages |
|
|
| Disadvantages |
|
|
| Common Uses |
|
|
| Best For |
|
|
| Version History |
Introduced: JDK 1.0 (1996)
Current Version: Part of java.util since Java 1.0 Status: Stable, widely used Evolution: XML properties variant added in Java 5 |
Introduced: 2001 (Douglas Crockford)
Current Version: RFC 8259 (2017) / ECMA-404 Status: Universal standard Evolution: JSON5, JSONC for comments, JSON Schema |
| Software Support |
Java: java.util.Properties (native)
Spring: @Value, @ConfigurationProperties IDEs: IntelliJ, Eclipse, VS Code Other: Apache Commons Configuration |
JavaScript: JSON.parse/stringify (native)
Python: json module (stdlib) Java: Jackson, Gson, org.json Tools: jq, fx, jsonlint, VS Code |
Why Convert Properties to JSON?
Converting Java Properties files to JSON is one of the most practical configuration migrations in modern software development. While properties files store everything as flat key=value strings, JSON provides true hierarchical nesting, data types (numbers, booleans, arrays), and universal language support. This conversion is essential when modernizing Java applications, building REST APIs, or integrating with JavaScript/Node.js ecosystems.
The dotted namespace convention in properties files maps perfectly to JSON's nested object structure. A property like spring.datasource.hikari.maximum-pool-size=20 becomes a deeply nested JSON path: spring.datasource.hikari["maximum-pool-size"]: 20. This transformation makes the implicit hierarchy explicit and adds type information -- the string "20" becomes the number 20, and "true" becomes the boolean true.
For Spring Boot applications, this conversion is particularly relevant because Spring Boot natively supports both application.properties and application.json. Teams migrating to JSON gain several advantages: comments can be added using JSON5 or JSONC (supported by VS Code), arrays can replace comma-separated string values, and IDE support for JSON schema validation provides autocomplete and error checking that properties files cannot offer.
JSON configuration is also the standard for cloud-native applications. AWS Lambda, Google Cloud Functions, Azure Functions, and Kubernetes ConfigMaps all work with JSON. Converting properties files to JSON enables seamless integration with cloud infrastructure tooling, Terraform configurations, and container orchestration platforms.
Key Benefits of Converting Properties to JSON:
- Nested Structure: Dotted namespaces become proper nested objects for clear hierarchy
- Data Types: Numbers, booleans, and arrays replace flat string values
- Universal Support: JSON is parsed natively by every programming language
- Schema Validation: JSON Schema enables IDE autocomplete and validation
- API Compatibility: Direct use in REST APIs and microservice communication
- Cloud Native: Compatible with AWS, GCP, Azure, and Kubernetes configurations
- Array Support: Comma-separated values become proper JSON arrays
Practical Examples
Example 1: Spring Boot Properties to Nested JSON
Input Properties file (application.properties):
# Database Configuration spring.datasource.url=jdbc:postgresql://db:5432/orders spring.datasource.username=app_user spring.datasource.hikari.maximum-pool-size=25 spring.datasource.hikari.minimum-idle=5 # Server server.port=8443 server.ssl.enabled=true server.compression.enabled=true server.compression.mime-types=application/json,text/html
Output JSON file (application.json):
{
"spring": {
"datasource": {
"url": "jdbc:postgresql://db:5432/orders",
"username": "app_user",
"hikari": {
"maximum-pool-size": 25,
"minimum-idle": 5
}
}
},
"server": {
"port": 8443,
"ssl": {
"enabled": true
},
"compression": {
"enabled": true,
"mime-types": ["application/json", "text/html"]
}
}
}
Example 2: Feature Flags to JSON Config
Input Properties file (features.properties):
# Feature Flags feature.dark-mode.enabled=true feature.dark-mode.rollout-percentage=75 feature.beta-api.enabled=false feature.beta-api.allowed-users=admin,tester,developer feature.cache.enabled=true feature.cache.ttl-seconds=3600 feature.cache.max-size=1000
Output JSON file (features.json):
{
"feature": {
"dark-mode": {
"enabled": true,
"rollout-percentage": 75
},
"beta-api": {
"enabled": false,
"allowed-users": ["admin", "tester", "developer"]
},
"cache": {
"enabled": true,
"ttl-seconds": 3600,
"max-size": 1000
}
}
}
Example 3: i18n Bundle to JSON for JavaScript Frontend
Input Properties file (messages_en.properties):
# English UI Translations ui.header.title=Welcome to Our App ui.header.subtitle=Manage your account ui.nav.home=Home ui.nav.dashboard=Dashboard ui.nav.settings=Settings ui.footer.copyright=2024 Example Corp ui.footer.privacy=Privacy Policy ui.footer.terms=Terms of Service
Output JSON file (en.json) for React/Vue i18n:
{
"ui": {
"header": {
"title": "Welcome to Our App",
"subtitle": "Manage your account"
},
"nav": {
"home": "Home",
"dashboard": "Dashboard",
"settings": "Settings"
},
"footer": {
"copyright": "2024 Example Corp",
"privacy": "Privacy Policy",
"terms": "Terms of Service"
}
}
}
Frequently Asked Questions (FAQ)
Q: How are dotted property names converted to nested JSON?
A: Each dot in a property name creates a new level of nesting in the JSON output. For example, spring.datasource.url=value becomes {"spring": {"datasource": {"url": "value"}}}. Properties sharing the same prefix are merged into the same object, preserving the logical grouping from the original file.
Q: Does the converter detect data types automatically?
A: Yes. The converter analyzes property values and assigns appropriate JSON types: numeric strings like "8080" become JSON numbers (8080), "true"/"false" become JSON booleans, comma-separated values become JSON arrays, and all other values remain strings. This intelligent type detection produces idiomatic JSON output.
Q: How are comma-separated values handled?
A: Comma-separated values like cors.origins=http://localhost,https://app.com are converted to JSON arrays: ["http://localhost", "https://app.com"]. This is particularly useful for Spring Boot properties that use comma-delimited lists for allowed origins, MIME types, or active profiles.
Q: Can Spring Boot use the JSON output directly?
A: Spring Boot supports application.json as a configuration source (via spring.config.import or SPRING_APPLICATION_JSON environment variable). The converted JSON file can replace application.properties directly, with all the same property bindings working through @ConfigurationProperties and @Value annotations.
Q: What happens to comments in the properties file?
A: Standard JSON (RFC 8259) does not support comments, so properties file comments are not included in the output. If you need comments, consider using JSONC (JSON with Comments) or JSON5 format, which are supported by VS Code, TypeScript, and other modern tools. You can also add a "_comment" field as a workaround.
Q: Can I use jq to process the converted JSON?
A: Absolutely. The output is valid JSON that works with jq for querying and transformation. For example, jq '.spring.datasource.url' extracts the database URL, and jq '.server.port' returns the port number as a JSON number. This makes it easy to integrate with shell scripts and CI/CD pipelines.
Q: How does this help with Kubernetes ConfigMaps?
A: Kubernetes ConfigMaps can store JSON data that applications read as configuration. Converting properties to JSON lets you store the entire application configuration as a single ConfigMap entry, mount it as a file, and read it with any JSON parser. This is cleaner than storing individual key-value pairs for complex configurations.
Q: Is the JSON output formatted or minified?
A: The converter produces pretty-printed JSON with 2-space indentation for readability. This human-readable format is ideal for configuration files checked into version control. If you need minified JSON for production use, you can process the output with tools like jq -c or JSON.stringify() without spacing arguments.