PHPackages                             taquillacom/gson-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. taquillacom/gson-php

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

taquillacom/gson-php
====================

Gson for PHP: Convert PHP objects to and from json

v0.10.0(3mo ago)01.1k↓50%MITPHPPHP &gt;=8.2

Since Nov 16Pushed 3mo agoCompare

[ Source](https://github.com/taquillacom/gson-php)[ Packagist](https://packagist.org/packages/taquillacom/gson-php)[ RSS](/packages/taquillacom-gson-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (14)Used By (0)

Gson PHP
========

[](#gson-php)

[![Build Status](https://camo.githubusercontent.com/d3e237f0aaae55f3d46a7b09695e94a0556a15f3978d6dbacc38b483f939ef19/68747470733a2f2f7472617669732d63692e6f72672f74656272752f67736f6e2d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/tebru/gson-php)[![Code Coverage](https://camo.githubusercontent.com/c39bf54dd8a951efa982e19329d9bd6c7bafb23768b03d344f023adb479b1220/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f74656272752f67736f6e2d7068702f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tebru/gson-php/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3ea96044dd95344411095bf5542fe1f2fd6a21f8334291b5d059c98c6edc13a4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f74656272752f67736f6e2d7068702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tebru/gson-php/?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/9d67a1d50eae783c6de29b0f2e6b74f8c0a89f6e24b7a898c6d7aca6549f9dd7/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f61633739646465302d316132662d343263612d623462362d3366663531336263663062352f6d696e692e706e67)](https://insight.sensiolabs.com/projects/ac79dde0-1a2f-42ca-b4b6-3ff513bcf0b5)

This library is a port of [google/gson](https://github.com/google/gson)written in PHP. Its purpose is to easily handle the conversion between PHP objects and JSON. It shares some of google/gson's goals such as:

- A simple interface using `toJson` and `fromJson` methods
- Enable serialization and deserialization of 3rd party classes
- Allow schema differences between PHP objects and JSON

And in addition:

- Utilize PHP 7 scalar type hints to be intelligent about property types
- Limit the number of annotations required to use
- Allow serialization decisions based on runtime information

Overview
--------

[](#overview)

Here are some simple use cases to get a feel for how the library works

If you have a PHP object you want to convert to JSON

```
// $object obtained elsewhere

$gson = Gson::builder()->build();
$json = $gson->toJson($object);
```

What this is doing is using the provided `GsonBuilder` to set up the `Gson` object with sensible defaults. Calling `Gson::toJson` and passing in an object will return a string of JSON.

If you need to, you can force the type Gson will use to serialize

```
// $object obtained elsewhere

$gson = Gson::builder()->build();
$json = $gson->toJson($object, MyCustomClass::class);
```

The reverse is very similar

```
// $json obtained elsewhere

$gson = Gson::builder()->build();
$fooObject = $gson->fromJson($json, Foo::class);
```

Now we call `Gson::fromJson` and pass in the json as a string and the type of object we'd like to map to. In this example, we will be getting an instantiated `Foo` object back.

Gson has a concept of "normalized" forms. This just means data that has been decoded with `json_decode`, or can be passed into `json_encode`.

```
// $object obtained elsewhere

$gson = Gson::builder()->build();
$jsonArray = $gson->toNormalized($object);
$object = $gson->fromNormalized($jsonArray, Foo::class);
```

Documentation
-------------

[](#documentation)

- [Customizing Serialization/Deserialization](docs/CustomSerializers.md)
- [Excluding Classes and Properties](docs/Exclusion.md)
- [Customizing Class Instantiation](docs/InstanceCreator.md)
- [Types](docs/Types.md)
- [Annotation Reference](docs/Annotations.md)
- [Advanced Usage](docs/Advanced.md)
- [Performance Considerations](docs/Performance.md)

Installation
------------

[](#installation)

This library requires PHP 7.1

```
composer require tebru/gson-php
```

Be sure and set up the annotation loader in one of your initial scripts.

```
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');

```

License
-------

[](#license)

This project is licensed under the MIT license. Please see the `LICENSE` file for more information.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance80

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~73 days

Total

12

Last Release

104d ago

PHP version history (2 changes)v0.7.6PHP &gt;=7.1

v0.9.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/ee938ee16441645cac906ff9e3e52977b8e1ccd568da1dd044c36e67b91c0b61?d=identicon)[taquillacom](/maintainers/taquillacom)

---

Top Contributors

[![natebrunette](https://avatars.githubusercontent.com/u/1831497?v=4)](https://github.com/natebrunette "natebrunette (244 commits)")[![urizev](https://avatars.githubusercontent.com/u/997364?v=4)](https://github.com/urizev "urizev (7 commits)")[![mattjanssen](https://avatars.githubusercontent.com/u/745319?v=4)](https://github.com/mattjanssen "mattjanssen (1 commits)")[![deegital](https://avatars.githubusercontent.com/u/239504?v=4)](https://github.com/deegital "deegital (1 commits)")[![samnela](https://avatars.githubusercontent.com/u/1852108?v=4)](https://github.com/samnela "samnela (1 commits)")[![taquillacom](https://avatars.githubusercontent.com/u/12511699?v=4)](https://github.com/taquillacom "taquillacom (1 commits)")[![nheimann1](https://avatars.githubusercontent.com/u/3142081?v=4)](https://github.com/nheimann1 "nheimann1 (1 commits)")[![Gounlaf](https://avatars.githubusercontent.com/u/236413?v=4)](https://github.com/Gounlaf "Gounlaf (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/taquillacom-gson-php/health.svg)

```
[![Health](https://phpackages.com/badges/taquillacom-gson-php/health.svg)](https://phpackages.com/packages/taquillacom-gson-php)
```

###  Alternatives

[symfony/serializer-pack

A pack for the Symfony serializer

1.1k28.2M221](/packages/symfony-serializer-pack)[thecodingmachine/graphqlite

Write your GraphQL queries in simple to write controllers (using webonyx/graphql-php).

5723.1M30](/packages/thecodingmachine-graphqlite)[json-mapper/json-mapper

Map JSON structures to PHP classes

2181.1M22](/packages/json-mapper-json-mapper)[tebru/gson-php

Gson for PHP: Convert PHP objects to and from json

152134.3k8](/packages/tebru-gson-php)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[psx/schema

Parse and generate data schema formats

57238.7k18](/packages/psx-schema)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
