OpenShot Audio Library | OpenShotAudio: juce::JSON Class Reference

OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
Classes | Public Types | Static Public Member Functions | List of all members
juce::JSON Class Reference

`#include <juce_JSON.h>`

## Classes
class | FormatOptions

## Public Types
enum class | Spacing { none , singleLine , multiLine }

## Static Public Member Functions
static Result | parse (const String &text, var &parsedResult)
static var | parse (const String &text)
static var | parse (const File &file)
static var | parse (InputStream &input)
static String | toString (const var &objectToFormat, bool allOnOneLine=false, int maximumDecimalPlaces=15)
static String | toString (const var &objectToFormat, const FormatOptions &formatOptions)
static var | fromString (StringRef)
static void | writeToStream (OutputStream &output, const var &objectToFormat, bool allOnOneLine=false, int maximumDecimalPlaces=15)
static void | writeToStream (OutputStream &output, const var &objectToFormat, const FormatOptions &formatOptions)
static String | escapeString (StringRef)
static Result | parseQuotedString (String::CharPointerType &text, var &result)

## Detailed Description

Contains static methods for converting JSON-formatted text to and from var objects.

The var class is structurally compatible with JSON-formatted data, so these functions allow you to parse JSON into a var object, and to convert a var object to JSON-formatted text.

See also
  var

Definition at line 38 of file juce_JSON.h.

## Member Enumeration Documentation

## ◆ Spacing

enum class juce::JSON::Spacing
| strong

Enumerator
none | All optional whitespace should be omitted.
singleLine | All output should be on a single line, but with some additional spacing, e.g. after commas and colons.
multiLine | Newlines and spaces will be included in the output, in order to make it easy to read for humans.

Definition at line 91 of file juce_JSON.h.

## Member Function Documentation

## ◆ escapeString()

String juce::JSON::escapeString | ( | StringRef | s | ) |
| static

Returns a version of a string with any extended characters escaped.

Definition at line 525 of file juce_JSON.cpp.

## ◆ fromString()

var juce::JSON::fromString | ( | StringRef | text | ) |
| static

Parses a string that was created with the toString() method. This is slightly different to the parse() methods because they will reject primitive values and only accept array or object definitions, whereas this method will handle either.

Definition at line 478 of file juce_JSON.cpp.

## ◆ parse() [1/4]

var juce::JSON::parse | ( | const File & | file | ) |
| static

Attempts to parse some JSON-formatted text from a file, and returns the result as a var object.

Note that this is just a short-cut for reading the entire file into a string and parsing the result.

If the parsing fails, this simply returns var() - if you need to find out more detail about the parse error, use the alternative parse() method which returns a Result.

Definition at line 494 of file juce_JSON.cpp.

## ◆ parse() [2/4]

var juce::JSON::parse | ( | const String & | text | ) |
| static

Attempts to parse some JSON-formatted text, and returns the result as a var object.

If the parsing fails, this simply returns var() - if you need to find out more detail about the parse error, use the alternative parse() method which returns a Result.

Note that this will only parse valid JSON, which means that the item given must be either an object or an array definition. If you want to also be able to parse any kind of primitive JSON object, use the fromString() method.

Definition at line 468 of file juce_JSON.cpp.

## ◆ parse() [3/4]

Result juce::JSON::parse | ( | const String & | text,
|  | var & | parsedResult )
| static

Parses a string of JSON-formatted text, and returns a result code containing any parse errors.

This will return the parsed structure in the parsedResult parameter, and will return a Result object to indicate whether parsing was successful, and if not, it will contain an error message.

If you're not interested in the error message, you can use one of the other shortcut parse methods, which simply return a var() if the parsing fails.

Note that this will only parse valid JSON, which means that the item given must be either an object or an array definition. If you want to also be able to parse any kind of primitive JSON object, use the fromString() method.

Definition at line 499 of file juce_JSON.cpp.

Referenced by parse(), parse(), and parse().

## ◆ parse() [4/4]

var juce::JSON::parse | ( | InputStream & | input | ) |
| static

Attempts to parse some JSON-formatted text from a stream, and returns the result as a var object.

Note that this is just a short-cut for reading the entire stream into a string and parsing the result.

If the parsing fails, this simply returns var() - if you need to find out more detail about the parse error, use the alternative parse() method which returns a Result.

Definition at line 489 of file juce_JSON.cpp.

## ◆ parseQuotedString()

Result juce::JSON::parseQuotedString | ( | String::CharPointerType & | text,
|  | var & | result )
| static

Parses a quoted string-literal in JSON format, returning the un-escaped result in the result parameter, and an error message in case the content was illegal. This advances the text parameter, leaving it positioned after the closing quote.

Definition at line 532 of file juce_JSON.cpp.

## ◆ toString() [1/2]

String juce::JSON::toString | ( | const var & | objectToFormat,
|  | bool | allOnOneLine = false,
|  | int | maximumDecimalPlaces = 15 )
| static

Returns a string which contains a JSON-formatted representation of the var object. If allOnOneLine is true, the result will be compacted into a single line of text with no carriage-returns. If false, it will be laid-out in a more human-readable format. The maximumDecimalPlaces parameter determines the precision of floating point numbers in scientific notation.

See also
  writeToStream

Definition at line 513 of file juce_JSON.cpp.

Referenced by toString().

## ◆ toString() [2/2]

String juce::JSON::toString | ( | const var & | objectToFormat,
|  | const FormatOptions & | formatOptions )
| static

Returns a string which contains a JSON-formatted representation of the var object, using formatting described by the FormatOptions parameter.

See also
  writeToStream

Definition at line 460 of file juce_JSON.cpp.

## ◆ writeToStream() [1/2]

void juce::JSON::writeToStream | ( | OutputStream & | output,
|  | const var & | objectToFormat,
|  | bool | allOnOneLine = false,
|  | int | maximumDecimalPlaces = 15 )
| static

Writes a JSON-formatted representation of the var object to the given stream. If allOnOneLine is true, the result will be compacted into a single line of text with no carriage-returns. If false, it will be laid-out in a more human-readable format. The maximumDecimalPlaces parameter determines the precision of floating point numbers in scientific notation.

See also
  toString

Definition at line 519 of file juce_JSON.cpp.

Referenced by toString(), and writeToStream().

## ◆ writeToStream() [2/2]

void juce::JSON::writeToStream | ( | OutputStream & | output,
|  | const var & | objectToFormat,
|  | const FormatOptions & | formatOptions )
| static

Writes a JSON-formatted representation of the var object to the given stream, using formatting described by the FormatOptions parameter.

See also
  toString

Definition at line 407 of file juce_JSON.cpp.

The documentation for this class was generated from the following files:

- juce_JSON.h
- juce_JSON.cpp