• Stars
    star
    127
  • Rank 281,967 (Top 6 %)
  • Language
    PHP
  • License
    GNU General Publi...
  • Created almost 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Generate Data Transfer Objects directly from JSON objects

Json 2 DTO

Build Status StyleCI Latest Version on Packagist Total Downloads

Spatie's Data Transfer Object library is awesome, but typing out DTOs can quickly become a chore. Inspired by Json2Typescript style tools, we built one for PHP DTOs.

Web Version

Try it out at https://json2dto.atymic.dev
The web version has all of the same tools as the cli version in an easy to use GUI. When generating nested DTOs, the tool will create a zip file.

CLI Tool

Prefer to use the tool locally? You can install json2dto via composer and generate files directly from json files.

composer global require atymic/json2dto # Install Globally

composer require atymic/json2dto --dev # Install locally in a project

Usage

The tool accepts json input either as a filename (second argument) or via stdin.
You should run the tool in the root of your project (where your composer.json is located) as it will resolve namespaces based on your PSR4 autoloading config. If you aren't using PSR4, your generated folder structure might not match.

Examples

# Generate PHP 7.4 typed DTO
./vendor/bin/json2dto generate "App\DTO" test.json -name "Test" --typed

# Generate PHP 8.0 typed DTO (DTO V3)
./vendor/bin/json2dto generate "App\DTO" test.json -name "Test" --v3

# Generate a flexible DTO (with nested DTOs)
./vendor/bin/json2dto generate "App\DTO" test.json -name "Test" --nested --flexible

# Generate a DTO from stdin
wget http://example.com/cat.json | ./vendor/bin/json2dto generate "App\DTO" -name Cat

Usage

json2dto generate [options] [--] <namespace> [<json>]

Arguments:
  namespace                       Namespace to generate the class(es) in
  json                            File containing the json string

Options:
      --nested                    Generate nested DTOs
      --typed                     Generate PHP >= 7.4 strict typing
      --flexible                  Generate a flexible DTO
      --dry                       Dry run, print generated files
      --v3                        Generate V3 DTO
  -h, --help                      Display this help message

More Repositories

1

twitter

Twitter API for Laravel 5.5+, 6.x, 7.x & 8.x
PHP
919
star
2

deployer-php-action

Deploy PHP projects using Deployer from Github Actions
TypeScript
60
star
3

zero-downtime-laravel-demo

Demo Repo for Zero Downtime Laravel Deployments with Github Actions
PHP
54
star
4

laravel-collection-playground

Test, Run & Share Laravel Collection Examples!
Vue
52
star
5

laravel-scaffold

Laravel + Inertia (Vue) + Tailwind Scaffold for new Projects
PHP
32
star
6

mylot-article-scraper

Scrapes historical mylot articles to PDF πŸ€–
JavaScript
29
star
7

todo-sync

Google Reminders to Todoist Sync
PHP
27
star
8

sitemap-ping-action

Ping search engines after deployments with Github actions
TypeScript
19
star
9

laravel-bulk-sqs-queue

Queue extension to allow dispatching bulk jobs (batch + async)
PHP
12
star
10

laravel-dateinterval-cast

DateInterval / CarbonInterval custom eloquent cast for Laravel 7.x+
PHP
12
star
11

laravel-twitter

Twitter API for Laravel 5.5+ & 6.x, based on thujohn/twitter
PHP
5
star
12

project_three_zero_ha

Project Three Zero Home Assistant Integration
Python
5
star
13

netlify-submit-sitemap

Submit sitemaps on deploy with Netlify
JavaScript
5
star
14

everyist

Create better reoccurring tasks for Todoist
Vue
3
star
15

sms-broadcast-php

PHP client for the SMS Broadcast API
PHP
3
star
16

docker-php-runner

Full featured PHP runner for PHP CI/CD builds & deployments.
Dockerfile
3
star
17

rsas-docker

Docker container for Rocket Streaming Audio Server
1
star
18

json2dto-php

[READONLY] Subtree split of atymic/json2dto for packagist
PHP
1
star
19

wave-invoice-export

Export all Wave / Waveapp invoices to PDF
JavaScript
1
star
20

indiehacker-quotes

Browser & Share Indiehacker's quotes
Vue
1
star
21

serverless-cobol

Certified Web Scale β„’ Β© 1962 International Business Machines, Inc
COBOL
1
star