Page MenuHomePhorge

final class PhutilJSON
libphutil Technical Documentation (Parsers)

Utilities for wrangling JSON.

Tasks

Formatting JSON Objects

No methods for this task.

Internals

  • private function encodeFormattedObject($object, $depth) — Pretty-print a JSON object.
  • private function encodeFormattedArray($array, $depth) — Pretty-print a JSON list.
  • private function encodeFormattedValue($value, $depth) — Pretty-print a JSON value.
  • private function getIndent($depth) — Render a string corresponding to the current indent depth.

Other Methods

  • public function __get($name)
  • public function __set($name, $value)
  • public function current()
  • public function key()
  • public function next()
  • public function rewind()
  • public function valid()
  • private function throwOnAttemptedIteration()
  • public function getPhobjectClassConstant($key, $byte_limit) — Read the value of a class constant.
  • public function encodeFormatted($object) — Encode an object in JSON and pretty-print it. This generates a valid JSON object with human-readable whitespace and indentation.
  • public function encodeAsList($list) — Encode a list in JSON and pretty-print it, discarding keys.

Methods

public function __get($name)
Inherited

This method is not documented.
Parameters
$name
Return
wild

public function __set($name, $value)
Inherited

This method is not documented.
Parameters
$name
$value
Return
wild

public function current()
Inherited

This method is not documented.
Return
wild

public function key()
Inherited

This method is not documented.
Return
wild

public function next()
Inherited

This method is not documented.
Return
wild

public function rewind()
Inherited

This method is not documented.
Return
wild

public function valid()
Inherited

This method is not documented.
Return
wild

private function throwOnAttemptedIteration()
Inherited

This method is not documented.
Return
wild

public function getPhobjectClassConstant($key, $byte_limit)
Inherited

Phobject

Read the value of a class constant.

This is the same as just typing self::CONSTANTNAME, but throws a more useful message if the constant is not defined and allows the constant to be limited to a maximum length.

Parameters
string$keyName of the constant.
int|null$byte_limitMaximum number of bytes permitted in the value.
Return
stringValue of the constant.

public function encodeFormatted($object)

Encode an object in JSON and pretty-print it. This generates a valid JSON object with human-readable whitespace and indentation.

Parameters
dict$objectAn object to encode in JSON.
Return
stringPretty-printed object representation.

public function encodeAsList($list)

Encode a list in JSON and pretty-print it, discarding keys.

Parameters
list<wild>$listList to encode in JSON.
Return
stringPretty-printed list representation.

private function encodeFormattedObject($object, $depth)

Pretty-print a JSON object.

Parameters
dict$objectObject to format.
int$depthCurrent depth, for indentation.
Return
stringPretty-printed value.

private function encodeFormattedArray($array, $depth)

Pretty-print a JSON list.

Parameters
list$arrayList to format.
int$depthCurrent depth, for indentation.
Return
stringPretty-printed value.

private function encodeFormattedValue($value, $depth)

Pretty-print a JSON value.

Parameters
dict$valueValue to format.
int$depthCurrent depth, for indentation.
Return
stringPretty-printed value.

private function getIndent($depth)

Render a string corresponding to the current indent depth.

Parameters
int$depthCurrent depth.
Return
stringIndentation.