2017 © Pedro Peláez
 

library json-browser

Helper library for working with JSON data

image

baacode/json-browser

Helper library for working with JSON data

  • Wednesday, February 28, 2018
  • by Erayd
  • Repository
  • 2 Watchers
  • 0 Stars
  • 32 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 15 Versions
  • 0 % Grown

The README.md

JSON Browser

Build Status Coverage Status Latest Stable Version License Maintainability, (*1)

Usage

use JsonBrowser\JsonBrowser;

// returns a new JsonBrowser, or throws an exception if the JSON syntax is invalid
$browser = new JsonBrowser();

// load document as JSON string
$browser->loadJSON($json);

// attach to existing document
$browser->attach($document);

// check for child node
$childExists = $browser->childExists('childName');

// get child node
$child = $browser->getChild('childName');
$child = $browser->childName; // dynamic __get() alias

// count child nodes
$numChildren = count($browser);
$numChildren = $browser->count();

// iterate through child nodes
foreach ($browser as $childName => $childNode) {
    // $childName is the index key of the child
    // $childNode is another JsonBrowser object (equivalent to $browser->getChild($childName))
}

// check for sibling node
$siblingExists = $child->siblingExists('siblingName');

// get sibling node
$child = $browser->getSibling('siblingName');

// get arbitrary node by path
$node = $browser->getNodeAt('#/childName/grandchildName/4');

// get arbitrary node value by path
$value = $browser->getValueAt('#/childName/grandchildName/4');

// set arbitrary node value by path
$browser->setValueAt('#/childName/grandchildName/4', 'myValue')

// delete arbitrary node value by path
$browser->deleteValueAt('#/childName/grandchildName/4')

// get root node
$root = $node->getRoot();

// test whether a node is the root
$nodeIsRoot = $node->isRoot();

// get parent node
$parent = $node->getParent();

// get node value
$value = $node->getValue();
$value = $parent->node; // __get() alias method when OPT_GET_VALUE is set

// set node value
$node->setValue('myValue');
$parent->node = 'myValue'; // __set() alias method

// delete node value
$node->deleteValue();

// get node type
$type = $node->getType();

// check whether the node exists
$nodeExists = $node->nodeExists();

// test whether the node is at least one of the given types
$isType = $node->isType(JsonBrowser::TYPE_STRING | JsonBrowser::TYPE_NUMBER);

// test whether the node is *not* any of the given types
$isNotType = $node->isNotType(JsonBrowser::TYPE_NULL | JsonBrowser::TYPE_INTEGER);

// test for equality
$isEqual = $node->isEqualTo("myValue");

// get node path
$path = $node->getPath();

// get JSON source for node
$json = $node->getJSON();

// get a node as the root of a subtree
$root = $node->asRoot();

// set named annotation on a node
$node->setAnnotation('myAnnotation', 'myValue'); // append to existing values
$node->setAnnotation('myOtherAnnotation', 'myOtherValue', true); // overwrite previous values

// get latest value for a named annotation, or null if not set
$annotation = $node->getAnnotation('myAnnotation');

// get array of values for a named annotation, empty array if not set
$annotations = $node->getAnnotations('myAnnotation');

// get an associative array of all annotations on a node, empty array if none set
$annotations = $node->getAnnotations();

Configuration Options

Name Description
OPT_DEFAULT Use the default options set (no user-configurable options enabled)
OPT_NONEXISTENT_EXCEPTIONS Throw an exception when attempting to read a nonexistent value
OPT_GET_VALUE Get values, rather than node objects, when using __get()
OPT_DECODE Decode the document passed to the constructor as a JSON string

Documentation

Comprehensive API documentation is available here., (*2)

Installation

To install via composer, use:, (*3)

$ composer require baacode/json-browser

Requirements

  • PHP >= 7.0
  • PHP's native JSON extension
  • PHP's native mbstring extension
  • seld/jsonlint >= 1.0

The Versions

28/02 2018

dev-master

9999999-dev https://github.com/baacode/json-browser

Helper library for working with JSON data

  Sources   Download

ISC

The Requires

 

The Development Requires

by Steve Gilberd

json helper browser

28/02 2018

v2.5.0

2.5.0.0 https://github.com/baacode/json-browser

Helper library for working with JSON data

  Sources   Download

ISC

The Requires

 

The Development Requires

by Steve Gilberd

json helper browser

22/02 2018

v2.4.0

2.4.0.0 https://github.com/baacode/json-browser

Helper classes for working with JSON data

  Sources   Download

ISC

The Requires

 

The Development Requires

by Steve Gilberd

json helper browser

04/02 2018

v2.3.0

2.3.0.0 https://github.com/baacode/json-browser

Helper classes for working with JSON data

  Sources   Download

ISC

The Requires

 

The Development Requires

by Steve Gilberd

json helper browser

29/01 2018

v2.2.0

2.2.0.0 https://github.com/baacode/json-browser

Helper classes for working with JSON data

  Sources   Download

ISC

The Requires

 

The Development Requires

by Steve Gilberd

json helper browser

29/01 2018

v2.1.1

2.1.1.0 https://github.com/baacode/json-browser

Helper classes for working with JSON data

  Sources   Download

ISC

The Requires

 

The Development Requires

by Steve Gilberd

json helper browser

23/01 2018

v2.1.0

2.1.0.0 https://github.com/baacode/json-browser

Helper classes for working with JSON data

  Sources   Download

ISC

The Requires

 

The Development Requires

by Steve Gilberd

json helper browser

21/01 2018

v2.0.0

2.0.0.0 https://github.com/baacode/json-browser

Helper classes for working with JSON data

  Sources   Download

ISC

The Requires

 

The Development Requires

by Steve Gilberd

json helper browser

20/01 2018

1.x-dev

1.9999999.9999999.9999999-dev https://github.com/baacode/json-browser

Helper classes for working with JSON data

  Sources   Download

ISC

The Requires

 

The Development Requires

by Steve Gilberd

json helper browser

20/01 2018

v1.5.0

1.5.0.0 https://github.com/baacode/json-browser

Helper classes for working with JSON data

  Sources   Download

ISC

The Requires

 

The Development Requires

by Steve Gilberd

json helper browser

04/01 2018

v1.4.0

1.4.0.0 https://github.com/baacode/json-browser

Helper classes for working with JSON data

  Sources   Download

ISC

The Requires

 

The Development Requires

by Steve Gilberd

json helper browser

16/11 2017

v1.3.0

1.3.0.0 https://github.com/baacode/json-browser

Helper classes for working with JSON data

  Sources   Download

ISC

The Requires

 

The Development Requires

by Steve Gilberd

json helper browser

14/11 2017

v1.2.0

1.2.0.0 https://github.com/baacode/json-browser

Helper classes for working with JSON data

  Sources   Download

ISC

The Requires

 

The Development Requires

by Steve Gilberd

json helper browser

14/11 2017

v1.1.0

1.1.0.0 https://github.com/baacode/json-browser

Helper classes for working with JSON data

  Sources   Download

ISC

The Requires

 

The Development Requires

by Steve Gilberd

json helper browser

14/11 2017

v1.0.0

1.0.0.0 https://github.com/baacode/json-browser

Helper classes for working with JSON data

  Sources   Download

ISC

The Requires

 

The Development Requires

by Steve Gilberd

json helper browser