Coder Social home page Coder Social logo

jacobdekeizer / json-to-php-generator Goto Github PK

View Code? Open in Web Editor NEW
62.0 62.0 18.0 4 MB

Generate PHP classes from json

Home Page: https://jacobdekeizer.github.io/json-to-php-generator

License: MIT License

JavaScript 1.36% HTML 0.72% Vue 24.68% TypeScript 71.76% SCSS 1.49%

json-to-php-generator's People

Contributors

dependabot[bot] avatar jacobdekeizer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

json-to-php-generator's Issues

Duplicate classes

Source

{
    "elements": {
        "test": 1,
        "elements": [
            {
                "elements": {
                    "test": 1,
                    "elements": []
                }
            }
        ]
    }
}

Result

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 Serializer attributes option

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;
}

Hierarchy

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

Export to Files

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.