PHPackages                             thomasbeaujean/json-annotation-bundle - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. thomasbeaujean/json-annotation-bundle

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

thomasbeaujean/json-annotation-bundle
=====================================

add the json annotation for an action

1.2.1(9y ago)030PHP

Since Mar 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/thomasbeaujean/JsonAnnotationBundle)[ Packagist](https://packagist.org/packages/thomasbeaujean/json-annotation-bundle)[ RSS](/packages/thomasbeaujean-json-annotation-bundle/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (6)DependenciesVersions (6)Used By (0)

JsonAnnotationBundle
====================

[](#jsonannotationbundle)

The JsonAnnotationBundle permits to use an annotation Json for your controller

Usage
=====

[](#usage)

Use the annotation @Json() in your controller

\#Configuration

Some parameters are optionnals:

```
	json_annotation:
			exception_code: 500 #the http code used for the exception
        	data_key: "data" # the key used to contains the data, it can be directly at the root, using the "" parameter
        	exception_message_key: "message" #the key for the exeception message
        	success_key: "success" #the key for the success (that is true is the result is ok, false for an exception)
        	post_query_back: false #do we send back the post parameters
        	post_query_key: "query" #the key for the post back parameters
            enable_authentication_error: false #A json response is sent back is the user is not authenticated or not granted

```

The reponse
-----------

[](#the-reponse)

### The normal response

[](#the-normal-response)

It is a json stream with the property 'success' with the true value and the property 'data' containing the array returned in the controller

### The exception response

[](#the-exception-response)

It is a json stream with the property 'success' with the false value and the property 'message' containing the error

Examples
========

[](#examples)

Import the bundle using composer
--------------------------------

[](#import-the-bundle-using-composer)

```
"tbn/json-annotation-bundle": "dev-master"

```

Import the bundle in your AppKernel
-----------------------------------

[](#import-the-bundle-in-your-appkernel)

```
new tbn\JsonAnnotationBundle\JsonAnnotationBundle()

```

The normal response Example
---------------------------

[](#the-normal-response-example)

```
use tbn\JsonAnnotationBundle\Configuration\Json;

class DefaultController extends Controller
{

     /**
      * The main view
      *
      * @Route("/someroute")
      * @Json()
      *
      * @return array
      */
     public function somerouteAction()
     {
         return array('data1' => 'value1', 'data2' => 'value2');
     }
  }

```

It will send back a json stream

```
 'success' => true
 'data'    => ['data1' => 'value1', 'data2' => 'value2']

```

The exception response
----------------------

[](#the-exception-response-1)

use tbn\\JsonAnnotationBundle\\Configuration\\Json;

```
 class DefaultController extends Controller
 {
     /**
      * The main view
      *
      * @Route("/someroute")
      * @Json()
      *
      * @return array
      */
     public function somerouteAction()
     {
	     throw \Exception('some error occured');
     }
 }

```

It will send back a json stream

```
 'success' => false
 'message'    => 'some error occured'

```

Events
======

[](#events)

A pre-hook event is dispatched at the beginning of the json response. It can be used to validate a token for example.

```
some_bundle.listener.json_token_validation_listener:
    class: "some_bundle\\Listener\\JsonTokenValidationListener"
    tags:
        - { name: kernel.event_listener, event: json.pre_hook, method: onJsonPrehook }

```

The method has one argument of type JsonPreHookEvent.

```
public function onJsonPrehook(JsonPreHookEvent $jsonPreHookEvent)

```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 54.8% 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 ~262 days

Total

4

Last Release

3287d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7ea8a2617988a793aef214fa41de59c562bd141343046102e6bf87d6db4cc354?d=identicon)[thomasbeaujean](/maintainers/thomasbeaujean)

---

Top Contributors

[![thomasbeaujean](https://avatars.githubusercontent.com/u/5817919?v=4)](https://github.com/thomasbeaujean "thomasbeaujean (17 commits)")[![paulandrieux](https://avatars.githubusercontent.com/u/1942078?v=4)](https://github.com/paulandrieux "paulandrieux (14 commits)")

---

Tags

annotationsjsonsymfony-bundle

### Embed Badge

![Health badge](/badges/thomasbeaujean-json-annotation-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/thomasbeaujean-json-annotation-bundle/health.svg)](https://phpackages.com/packages/thomasbeaujean-json-annotation-bundle)
```

PHPackages © 2026

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