A powerful Laravel package for converting between JSON and Toon format. Seamlessly transform your JSON data into a compact, human-readable Toon format and back again.
You can install the package via Composer:
composer require knackline/laravel-toon
The package will automatically register its service provider and facade.
use Knackline\LaravelToon\Toon;
$jsonData = [
"context" => [
"task" => "Our favorite hikes together",
"location" => "Boulder",
"season" => "spring_2025"
],
"friends" => ["ana", "luis", "sam"],
"hikes" => [
[
"id" => 1,
"name" => "Blue Lake Trail",
"distanceKm" => 7.5,
"elevationGain" => 320,
"companion" => "ana",
"wasSunny" => true
]
]
];
$toon = Toon::fromJson($jsonData);
Output:
context:
task: Our favorite hikes together
location: Boulder
season: spring_2025
friends[3]: ana,luis,sam
hikes[3]{id,name,distanceKm,elevationGain,companion,wasSunny}:
1,Blue Lake Trail,7.5,320,ana,true
2,Ridge Overlook,9.2,540,luis,false
3,Wildflower Loop,5.1,180,sam,true
$toonString = "context:
task: Our favorite hikes together
location: Boulder
season: spring_2025
friends[3]: ana,luis,sam
hikes[3]{id,name,distanceKm,elevationGain,companion,wasSunny}:
1,Blue Lake Trail,7.5,320,ana,true
2,Ridge Overlook,9.2,540,luis,false";
$jsonData = Toon::toJson($toonString);
If you prefer using facades:
use Knackline\LaravelToon\Facades\Toon;
$toon = Toon::fromJson($data);
$json = Toon::toJson($toon);
key: value
key:
nestedKey: value
anotherKey: value
key[count]: value1,value2,value3
key[count]{field1,field2,field3}:
value1,value2,value3
value4,value5,value6
7.5, 320)true and falseThe MIT License (MIT). Please see the License File for more information.
For issues, questions, or contributions, please visit the GitHub repository.
How can I help you explore Laravel packages today?