PHP code example of tarikweiss / tjson

1. Go to this page and download the library: Download tarikweiss/tjson library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tarikweiss / tjson example snippets


class ClassToConvert
{
    #[\Tjson\Attributes\MappedPropertyName(name: 'public_item')]
    public $publicItem;
    
    protected $protectedItem;
    
    private $privateItem;
    
    #[\Tjson\Attributes\MappedPropertyClass(class: ClassC::class)]
    private ClassA|ClassB|ClassC $typedItems;
    
    /**
     * @\Tjson\Attributes\Required(

$jsonDecoder = new \Tjson\JsonDecoder();

$yourClassInstance = $jsonDecoder->decodeByClassName($jsonString, \Your\Class::class)
echo $yourClassInstance->getProtectedItem() // 1337

$jsonEncoder = new \Tjson\JsonEncoder();

$jsonString = $jsonEncoder->encode($yourClassInstance);