TEasyJson
is a powerful and intuitive Delphi class that simplifies JSON manipulation. Designed with a fluent interface, it enables developers to seamlessly create, modify, and traverse JSON objects and arrays using method chaining. Whether handling simple key-value pairs or deeply nested structures, TEasyJson
ensures efficiency, readability, and flexibility.
- π Fluent interface for effortless JSON manipulation
- π Supports both JSON objects and arrays
- π Chainable methods for concise and readable code
- ποΈ Easily constructs and modifies nested JSON structures
- π¨ Provides formatted JSON output for better readability
- β‘ Optimized for performance and efficiency
Getting started with TEasyJson
is quick and easy:
- Copy
TEasyJson.pas
into your project. - Add
TEasyJson
to youruses
clause. - Start Coding! Enjoy simplified JSON handling with method chaining.
var EJ: TEasyJson;
begin
EJ := TEasyJson.Create;
EJ.Put('name', 'Alice')
.Put('age', 25)
.AddArray('hobbies')
.Put(0, 'Reading')
.Put(1, 'Cycling');
WriteLn(EJ.Format());
end;
{
"name": "Alice",
"age": 25,
"hobbies": [
"Reading",
"Cycling"
]
}
var EJ: TEasyJson;
begin
EJ := TEasyJson.Create('{"name":"John","age":30}');
WriteLn(EJ.Format());
end;
EJ.Put('email', 'alice@example.com');
EJ.Put('age', 26); // Updates existing key
var EJ: TEasyJson;
begin
EJ := TEasyJson.Create;
EJ.AddArray('numbers')
.Put(0, 10)
.Put(1, 20)
.Put(2, 30);
WriteLn(EJ.Format());
end;
EJ.AddObject('address',
function(E: TEasyJson): TEasyJson
begin
Result := E.Put('city', 'New York')
.Put('zip', '10001');
end);
WriteLn(EJ['name'].AsString); // Alice
WriteLn(EJ['age'].AsInteger); // 26
WriteLn(EJ['hobbies'][1].AsString); // Cycling
The TEasyJson
class provides a robust set of methods and properties for seamless JSON manipulation.
Create()
β Creates an empty JSON object.Create(const AJson: string)
β Parses a JSON string.Create(const AJsonValue: TJSONValue)
β Wraps an existing JSON value.
Put(AKey: string; AValue: Variant): TEasyJson
β Adds or updates a key.Put(AIndex: Integer; AValue: Variant): TEasyJson
β Sets an array element.Add(AKey: string; AValue: Variant): TEasyJson
β Adds a new key-value pair.AddArray(AKey: string): TEasyJson
β Adds an empty array.AddObject(AKey: string; AFunc: TFunc<TEasyJson, TEasyJson>): TEasyJson
β Adds a nested object.ToString(): string
β Returns a compact JSON string.Format(): string
β Returns formatted JSON.Count(): Integer
β Returns the number of elements.AsString(): string
β Converts a JSON value to a string.AsInt32r(): Int32
β Converts a JSON value to an int32.AsFloat(): Double
β Converts a JSON value to a float.AsBoolean(): Boolean
β Converts a JSON value to a boolean.
Items[AKeyOrIndex: Variant]: TEasyJson
β Accesses elements by key or index.
See EasyJson.pas
for the full documented API.
- π Report Issues: GitHub Issue Tracker
- π¬ Join the Community: Forum | Discord
- π Learn Delphi: Learn Delphi
We welcome contributions to EasyJson! π
- π Report Bugs β Help improve
TEasyJson
by submitting issues. - β¨ Suggest Features β Share ideas to enhance its functionality.
- π§ Submit Pull Requests β Improve the codebase and add features.
EasyJson is distributed under the BSD-3-Clause License, allowing redistribution and modification in both source and binary forms. See the LICENSE for details.
Your support keeps EasyJson evolving! If you find this library useful, please consider sponsoring the project. Every contribution helps drive future enhancements and innovations.
- β Star the repo β Show your appreciation.
- π’ Share with your network β Spread the word.
- π Report bugs β Help improve
TEasyJson
. - π§ Submit fixes β Contribute by fixing issues.
- π‘ Suggest features β Help shape its future.
π Every contribution makes a difference β thank you for being part of the journey!
π₯ EasyJson β Effortless JSON Handling for Delphi with Fluent Simplicity.