jacobdekeizer / json-to-php-generator Goto Github PK
View Code? Open in Web Editor NEWGenerate PHP classes from json
Home Page: https://jacobdekeizer.github.io/json-to-php-generator
License: MIT License
Generate PHP classes from json
Home Page: https://jacobdekeizer.github.io/json-to-php-generator
License: MIT License
I tottaly missed the download button as it's a really small grey icon. It would help to show some text and make it a different color
{
"elements": {
"test": 1,
"elements": [
{
"elements": {
"test": 1,
"elements": []
}
}
]
}
}
final class RootObject
{
public Elements $elements;
}
final class Elements
{
public int $test;
/** @var Elements[] */
public array $elements;
}
final class Elements
{
public Elements $elements;
}
final class Elements
{
public int $test;
public array $elements;
}
Add support for selecting the "attributes for JMS Serializers" option
use JMS\Serializer\Annotation\Type;
final readonly class Example {
#[Type('array<string>')]
public array $list;
}
Exemple:
{
"data": [
{
"id": 1,
"name": "bob",
"categories": [
{
"name": "test"
}
]
}
]
}
We get with default options:
<?php
class RootObject
{
/** @var Data[] */
public array $data;
/**
* @param Data[] $data
*/
public function __construct(array $data)
{
$this->data = $data;
}
}
<?php
class Data
{
public int $id;
public string $name;
/** @var Categories[] */
public array $categories;
/**
* @param Categories[] $categories
*/
public function __construct(
int $id,
string $name,
array $categories
) {
$this->id = $id;
$this->name = $name;
$this->categories = $categories;
}
}
<?php
class Categories
{
public string $name;
public function __construct(string $name)
{
$this->name = $name;
}
}
It will be nice if in "[Namespace / Class]" we have an option to keep hierarchy and have something like:
<?php
namespace Demo;
class RootObject
{
/** @var Data[] */
public array $data;
/**
* @param Data[] $data
*/
public function __construct(array $data)
{
$this->data = $data;
}
}
<?php
namespace Demo\RootObject;
class Data
{
public int $id;
public string $name;
/** @var Categories[] */
public array $categories;
/**
* @param Categories[] $categories
*/
public function __construct(
int $id,
string $name,
array $categories
) {
$this->id = $id;
$this->name = $name;
$this->categories = $categories;
}
}
<?php
namespace Demo\RootObject\Data;
class Categories
{
public string $name;
public function __construct(string $name)
{
$this->name = $name;
}
}
And a folder structure following it, beacause on big json is bit a mess
Thanks for your nice project
It's a chore to copy and create files individually and would be great to be able to download them all using something like this
Great job on the app, it works great!
This looks very good, but I'm looking at converting complex and large JSON structures. Copying over everything one by one into files is rather tedious. Having a functionality to export all the classes individually would be awesome!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.