W3cubDocs

/Pony

JsonDoc

[Source]

Top level JSON type containing an entire document. A JSON document consists of exactly 1 value.

class ref JsonDoc

Constructors

create

[Source]

Default constructor building a document containing a single null.

new ref create()
: JsonDoc ref^

Returns

Public fields

var data: (F64 val | I64 val | Bool val |

[None](builtin-None.md) val | [String](builtin-String.md) val | [JsonArray](json-JsonArray.md) ref | 
[JsonObject](json-JsonObject.md) ref)

[Source]

The parsed JSON structure.

Will be a None if parse(source: String) has not been called yet.

Public Functions

string

[Source]

Generate string representation of this document.

fun box string(
  indent: String val = "",
  pretty_print: Bool val = false)
: String val

Parameters

  • indent: String val = ""
  • pretty_print: Bool val = false

Returns

parse

[Source]

Parse the given string as a JSON file, building a document. Raise error on invalid JSON in given source.

fun ref parse(
  source: String val)
: None val ?

Parameters

Returns

parse_report

[Source]

Give details of the error that occurred last time we attempted to parse. If parse was successful returns (0, "").

fun box parse_report()
: (USize val , String val)

Returns

Private Functions

_parse_value

[Source]

Parse a single JSON value of any type, which MUST be present. Raise error on invalid or missing value.

fun ref _parse_value(
  context: String val)
: (F64 val | I64 val | Bool val | 
    None val | String val | JsonArray ref | 
    JsonObject ref) ?

Parameters

Returns

_parse_keyword

[Source]

Parse a keyword, the first letter of which has already been peeked.

fun ref _parse_keyword()
: (Bool val | None val) ?

Returns

_parse_number

[Source]

Parse a number, the leading character of which has already been peeked.

fun ref _parse_number()
: (F64 val | I64 val) ?

Returns

_parse_decimal

[Source]

Parse a decimal integer which must appear immediately in the source.

fun ref _parse_decimal()
: (I64 val , U8 val) ?

Returns

_parse_object

[Source]

Parse a JSON object, the leading { of which has already been peeked.

fun ref _parse_object()
: JsonObject ref ?

Returns

_parse_array

[Source]

Parse an array, the leading [ of which has already been peeked.

fun ref _parse_array()
: JsonArray ref ?

Returns

_parse_string

[Source]

Parse a string, which must be the next thing found, other than whitesapce.

fun ref _parse_string(
  context: String val)
: String val ?

Parameters

Returns

_parse_escape

[Source]

Process a string escape sequence, the leading \ of which has already been consumed.

fun ref _parse_escape()
: String val ?

Returns

_parse_unicode_escape

[Source]

Process a Unicode escape sequence, the leading \u of which has already been consumed.

fun ref _parse_unicode_escape()
: String val ?

Returns

_parse_unicode_digits

[Source]

Parse the hex digits of a Unicode escape sequence, the leading \u of which has already been consumed, and return the encoded character value.

fun ref _parse_unicode_digits()
: U32 val ?

Returns

_dump_whitespace

[Source]

Dump all whitespace at the current read location in source, if any.

fun ref _dump_whitespace()
: None val

Returns

_peek_char

[Source]

Peek the next char in the source, without consuming it. If an eof_context is given then an error is thrown on eof, setting a suitable message. If eof_context is None then 0 is returned on EOF. It up to the caller to handle this appropriately.

fun ref _peek_char(
  eof_context: (String val | None val) = reference)
: U8 val ?

Parameters

  • eof_context: (String val | None val) = reference

Returns

  • U8 val ?

_get_char

[Source]

Get and consume the next char in the source. If an eof_context is given then an error is thrown on eof, setting a suitable message. If eof_context is None then 0 is returned on EOF. It up to the caller to handle this appropriately.

fun ref _get_char(
  eof_context: (String val | None val) = reference)
: U8 val ?

Parameters

  • eof_context: (String val | None val) = reference

Returns

  • U8 val ?

_last_char

[Source]

Get the last character peeked or got from the source as a String. For use generating error messages.

fun ref _last_char()
: String val

Returns

_error

[Source]

Record an error with the given message.

fun ref _error(
  msg: String val)
: None val

Parameters

Returns

© 2016-2018, The Pony Developers
© 2014-2015, Causality Ltd.
Licensed under the BSD 2-Clause License.
https://stdlib.ponylang.io/json-JsonDoc