2017 © Pedro Peláez
 

library mongo-json

A helper library for serializing MongoDB types to JSON string

image

mtrbean/mongo-json

A helper library for serializing MongoDB types to JSON string

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

MongoJson

A small library that JSON encode an Mongo document that contains MongoDB-specific types (e.g. MongoDate)., (*1)

If you just use json_encode(), you will get some PHP specific results that makes it very difficult to interface with other part of your program. This library attempts to implement the 'strict mode' and also the 'javascript (JSONP) mode' defined in http://docs.mongodb.org/manual/reference/mongodb-extended-json/, (*2)

Installation using Composer

Create a composer.json file in your project root:, (*3)

{
    "require": {
        "mtrbean/mongo-json": "1.*"
    }
}

Install via composer:, (*4)

php composer.phar install

P.S. If you haven't already been using composer for managing your dependency, you can install it via:, (*5)

curl -sS https://getcomposer.org/installer | php

Autoload

You can have the class MongoJson autoloaded using the mechanism provided by composer:, (*6)

require 'vendor/autoload.php';

Usage

Strict Mode

$doc = array("dt" => new MongoDate);
echo MongoJson::strict($doc);

will print:, (*7)

{"dt":{"$date":1371525158000}}

Extended Mode

$doc = array("dt" => new MongoDate);
echo MongoJson::extended($doc);

will print:, (*8)

{"dt":new Date(1371525158000)}

Options

You can pass extra options that you can normally use with json_encode(), (*9)

$doc = array("_id" => new MongoId, "regex" => new MongoRegex('/^acme.*corp/i'));
echo MongoJson::extended($doc, JSON_PRETTY_PRINT); // will prettify the JSON string

will print:, (*10)

{
    "_id": {
        "$oid": "51bfcdd71ede01d61a000000"
    },
    "regex": /^acme.*corp/i
}

License

MIT, (*11)

Contribute

Feel free to fork and submit pull requests!, (*12)

The Versions

24/06 2013

dev-master

9999999-dev

A helper library for serializing MongoDB types to JSON string

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

mongodb database json

24/06 2013

1.1.0

1.1.0.0

A helper library for serializing MongoDB types to JSON string

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

mongodb database json

19/06 2013

1.0.1

1.0.1.0

A helper library for serializing MongoDB types to JSON string

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

mongodb database json

18/06 2013

1.0.0

1.0.0.0

A helper library for serializing MongoDB types to JSON string

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

mongodb database json