Find file
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (37 sloc) 1.07 KB

Jbuilder (for PHP)

A PHP port based loosely on the original:

Jbuilder gives you a simple DSL for declaring JSON structures that beats massaging giant hash structures. This is particularly helpful when the generation process is fraught with conditionals and loops. Here's a simple example:


$json = JBuilder::encode(function($json) {
  $json->name = 'Dennis';

  $json->address(function($json) {
    $json->street = 'Cambridge St';
    $json->city = 'Melbourne';

  $json->comments(array("hello", "world"), function($json, $comment) {
    return "Comment: ".$comment;

This will build the following structure:

  "address": {
    "city": "Melbourne", 
    "street": "Cambridge St"
  "comments": [
    "Comment: hello", 
    "Comment: world"
  "name": "Dennis"


Tests are located in the tests subdirectory.

You'll need to install PHPUnit before running the tests:

Then run the tests like this: