JsonDot: Write JSON Code That Reads Like a Thought
- Coding Camp
- 8 hours ago
- 3 min read
Have you ever looked at your Java code and thought: “There’s no way all this just to get one field out of a JSON object makes sense.”
If you've battled with long chains of getJSONObject().getJSONArray() and wondered if there's a cleaner way — you're not imagining things. Java’s default way of working with JSON can feel like wrestling a machine just to say something simple.
That’s why JsonDot — a lightweight Java library that brings back joy and elegance to JSON handling. With dot-notation path access, deep merge, XML conversion, and smart array querying, you can focus on logic, not on boilerplate.
It’s like giving your Java code a breath of fresh air.
What is JsonDot?
JsonDot is a modern Java library that simplifies working with JSON. It allows intuitive dot-notation access to deeply nested fields, smartly handles arrays, supports XML conversion, and includes helpful utilities like path validation and deep merging.
It's built for real-world use cases like configuration management, API response parsing, and data transformation — with performance and readability in mind.
🔑 Key Features
1. Dot Notation Path Access
Access deeply nested fields with just one line:
JsonDot jsonDot = new JsonDot();
JSONObject json = new JSONObject("{\"user\":{\"name\":\"John\"}}");
String name = jsonDot.get(json, "user.name", String.class);
2. Array Support
Index-based: users[0].name
Wildcard: users[*].name
Filter and map arrays using predicates
3. Utility Methods
✅ Deep Merge
Merge two JSON objects without overwriting nested structures:
JSONObject target = new JSONObject("{\"user\":{\"name\":\"John\",\"age\":30}}");
JSONObject source = new JSONObject("{\"user\":{\"age\":31,\"city\":\"NY\"}}");
JSONObject merged = JsonUtils.deepMerge(target, source);
🔄 XML Conversion
// JSON to XML
String xml = JsonUtils.toXml(json);
// XML to JSON
JSONObject json = JsonUtils.fromXml(xml);
🔍 JSON Validation
boolean isValid = JsonUtils.isValidJson("{\"key\":\"value\"}");
💡 Common Use Cases
API Response Handling
JsonDot response = new JsonDot(apiResponse);
List<Object> items = response.query("data.items.*");
Data Transformation
JsonDot source = new JsonDot(sourceData);
JsonDot target = new JsonDot();
target.addElement("user.name", source.getString("name")) .addElement("user.age", source.getInt("age"));
🔍 Advanced Features
Path Validation
if (jsonDot.isValidPath("user.address.city")){
String city = jsonDot.get(json, "user.address.city", String.class);
}
Array Filtering
List<JSONObject> filtered = jsonDot.filterArray( json, "products", product -> product.getInt("price") > 100 );
Type-Safe Accessors
String name = jsonDot.getAsString(json, "user.name");
int age = jsonDot.getAsInt(json, "user.age");
boolean active = jsonDot.getAsBoolean(json, "user.active");
✅ Best Practices
Use isValidPath to avoid runtime path errors
Prefer type-safe methods for predictable casting
Handle JsonDotException for invalid operations
Cache common paths if performance is critical
Use JsonArrayDot for array-heavy workflows
⚙️ Performance Considerations
Memory-efficient and fast
Optimized for repeated access
Comparable speed with other popular libraries
No reflection, minimal dependencies
📦 Getting Started
Add this to your pom.xml:
<dependency>
<groupId>tech.coderscamp.jsondot</groupId> <artifactId>jsondot</artifactId>
<version>1.0.0</version>
</dependency>
🤝 Why Use JsonDot?
JsonDot was built out of practical frustrations and real engineering needs. It's not just a wrapper—it's a rethinking of how we should work with JSON in Java:
Clean, expressive code
Fewer lines, fewer bugs
Powerful features when you need them
Minimal setup — ready to use in minutes
If you're building anything in Java that touches JSON — whether it's a microservice, a CLI tool, or a large backend system — JsonDot is here to make your life easier.
🔗 Learn More
You can find the code, documentation, and usage examples on GitHub.
Thank you for joining me on this journey with JsonDot! I’d love to hear your thoughts, ideas, or ways you plan to use it.
If JsonDot made your work a little easier or inspired you in any way, that’s the greatest reward. Stay tuned for more updates!
Bình luận