Overview
simple_json is a production-ready JSON library for Eiffel that builds on the standard eJSON library to provide modern features. It offers JSON Schema validation (Draft 7), JSON Pointer navigation (RFC 6901), JSON Patch operations (RFC 6902), JSON Merge Patch (RFC 7386), JSONPath queries, and comprehensive error tracking.
Part of the Simple Eiffel ecosystem.
Quick Start
Installation
- Set the environment variable:
export SIMPLE_EIFFEL=/d/prod - Add to your ECF file:
<library name="simple_json" location="$SIMPLE_EIFFEL/simple_json/simple_json.ecf"/>
Parse & Navigate
local
json: SIMPLE_JSON
value: SIMPLE_JSON_VALUE
do
create json
if attached json.parse ('{"users": [{"name": "Alice"}]}') as v then
-- Use JSONPath query
print (json.query_string (v, "$.users[0].name")) -- "Alice"
end
end
Build JSON
local
obj: SIMPLE_JSON_OBJECT
do
obj := json.new_object
.put_string ("name", "Alice")
.put_integer ("age", 30)
.put_boolean ("active", True)
print (obj.to_json)
-- {"name":"Alice","age":30,"active":true}
end
Key Features
JSON Schema Validation
Draft 7 support - the only Eiffel library with JSON Schema validation.
JSON Pointer (RFC 6901)
Navigate JSON with simple path expressions like "/users/0/name".
JSON Patch (RFC 6902)
Standardized add, remove, replace, move, copy, and test operations.
JSON Merge Patch
RFC 7386 declarative merging for configuration overlays.
JSONPath Queries
SQL-like queries with wildcards: "$.users[*].name".
Streaming Parser
Process gigabyte-sized JSON files with constant memory.
Decimal Precision
Exact decimal values via simple_decimal - no floating-point artifacts.
Decimal Precision
For financial data or any values requiring exact representation, use put_decimal
instead of put_real. This prevents floating-point artifacts like 19.99 becoming
19.989999999999998.
The Problem with REAL
-- Using put_real
obj.put_real (19.99, "price")
-- Output: {"price": 19.989999999999998}
The Solution with SIMPLE_DECIMAL
local
price: SIMPLE_DECIMAL
do
create price.make ("19.99")
obj.put_decimal (price, "price")
-- Output: {"price": 19.99}
end
Decimal API
| Method | Description |
|---|---|
put_decimal (value, key) |
Store exact decimal value in object |
decimal_item (key) |
Retrieve value as SIMPLE_DECIMAL |
add_decimal (value) |
Add decimal to array |
as_decimal |
Convert any JSON number to SIMPLE_DECIMAL |
Documentation
- User Guide - Complete tutorial with examples
- API Reference - Full feature documentation
- Architecture - Internal design and rationale
- Cookbook - Real-world recipes and patterns