Skip to content

mrbenosborne/json-unmarshal

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

JSON Unmarshal

A PHP package for un-marshalling JSON data onto a class properties.

Build Latest Stable Version Latest Unstable Version License composer.lock

Install

Install via composer.

composer require mrbenosborne/json-unmarshal

Example

Below is an example of a Flight class, the full example can be found in the examples/ folder.

<?php

use JSON\Attributes\JSON;
use JSON\Unmarshal;

include '../vendor/autoload.php';
include 'FlightRoute.php';

/**
 * Class Flight
 */
class Flight
{
    #[JSON(field: 'airline')]
    public string $airlineName;

    #[JSON(field: 'aircraft.type')]
    public string $aircraftType;

    #[JSON(field: 'route', type: FlightRoute::class)]
    public array $route;
}

// Create a new flight class
$flight = new Flight();

// Load our JSON data from file
$jsonData = json_decode(file_get_contents('flight.json'), true);

// Unmarshal JSON
Unmarshal::decode($flight, $jsonData);

About

A PHP package for un-marshalling/marshalling JSON.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages