Create JSON structures via a Builder-style DSL
PHP
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
tests
README.md
demo.php
phpunit.xml

README.md

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:

<?php

$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

Tests are located in the tests subdirectory.

You'll need to install PHPUnit before running the tests: http://www.phpunit.de/manual/3.5/en/installation.html

Then run the tests like this:

phpunit