OpenShot Library | OpenShotAudio 0.2.2
juce_JSON.h
1
2/** @weakgroup juce_core-javascript
3 * @{
4 */
5/*
6 ==============================================================================
7
8 This file is part of the JUCE library.
9 Copyright (c) 2017 - ROLI Ltd.
10
11 JUCE is an open source library subject to commercial or open-source
12 licensing.
13
14 The code included in this file is provided under the terms of the ISC license
15 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16 To use, copy, modify, and/or distribute this software for any purpose with or
17 without fee is hereby granted provided that the above copyright notice and
18 this permission notice appear in all copies.
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27namespace juce
28{
29
30//==============================================================================
31/**
32 Contains static methods for converting JSON-formatted text to and from var objects.
33
34 The var class is structurally compatible with JSON-formatted data, so these
35 functions allow you to parse JSON into a var object, and to convert a var
36 object to JSON-formatted text.
37
38 @see var
39
40 @tags{Core}
41*/
43{
44public:
45 //==============================================================================
46 /** Parses a string of JSON-formatted text, and returns a result code containing
47 any parse errors.
48
49 This will return the parsed structure in the parsedResult parameter, and will
50 return a Result object to indicate whether parsing was successful, and if not,
51 it will contain an error message.
52
53 If you're not interested in the error message, you can use one of the other
54 shortcut parse methods, which simply return a var() if the parsing fails.
55
56 Note that this will only parse valid JSON, which means that the item given must
57 be either an object or an array definition. If you want to also be able to parse
58 any kind of primitive JSON object, use the fromString() method.
59 */
60 static Result parse (const String& text, var& parsedResult);
61
62 /** Attempts to parse some JSON-formatted text, and returns the result as a var object.
63
64 If the parsing fails, this simply returns var() - if you need to find out more
65 detail about the parse error, use the alternative parse() method which returns a Result.
66
67 Note that this will only parse valid JSON, which means that the item given must
68 be either an object or an array definition. If you want to also be able to parse
69 any kind of primitive JSON object, use the fromString() method.
70 */
71 static var parse (const String& text);
72
73 /** Attempts to parse some JSON-formatted text from a file, and returns the result
74 as a var object.
75
76 Note that this is just a short-cut for reading the entire file into a string and
77 parsing the result.
78
79 If the parsing fails, this simply returns var() - if you need to find out more
80 detail about the parse error, use the alternative parse() method which returns a Result.
81 */
82 static var parse (const File& file);
83
84 /** Attempts to parse some JSON-formatted text from a stream, and returns the result
85 as a var object.
86
87 Note that this is just a short-cut for reading the entire stream into a string and
88 parsing the result.
89
90 If the parsing fails, this simply returns var() - if you need to find out more
91 detail about the parse error, use the alternative parse() method which returns a Result.
92 */
93 static var parse (InputStream& input);
94
95 //==============================================================================
96 /** Returns a string which contains a JSON-formatted representation of the var object.
97 If allOnOneLine is true, the result will be compacted into a single line of text
98 with no carriage-returns. If false, it will be laid-out in a more human-readable format.
99 The maximumDecimalPlaces parameter determines the precision of floating point numbers
100 in scientific notation.
101 @see writeToStream
102 */
103 static String toString (const var& objectToFormat,
104 bool allOnOneLine = false,
105 int maximumDecimalPlaces = 15);
106
107 /** Parses a string that was created with the toString() method.
108 This is slightly different to the parse() methods because they will reject primitive
109 values and only accept array or object definitions, whereas this method will handle
110 either.
111 */
112 static var fromString (StringRef);
113
114 /** Writes a JSON-formatted representation of the var object to the given stream.
115 If allOnOneLine is true, the result will be compacted into a single line of text
116 with no carriage-returns. If false, it will be laid-out in a more human-readable format.
117 The maximumDecimalPlaces parameter determines the precision of floating point numbers
118 in scientific notation.
119 @see toString
120 */
121 static void writeToStream (OutputStream& output,
122 const var& objectToFormat,
123 bool allOnOneLine = false,
124 int maximumDecimalPlaces = 15);
125
126 /** Returns a version of a string with any extended characters escaped. */
127 static String escapeString (StringRef);
128
129 /** Parses a quoted string-literal in JSON format, returning the un-escaped result in the
130 result parameter, and an error message in case the content was illegal.
131 This advances the text parameter, leaving it positioned after the closing quote.
132 */
133 static Result parseQuotedString (String::CharPointerType& text, var& result);
134
135private:
136 //==============================================================================
137 JSON() = delete; // This class can't be instantiated - just use its static methods.
138};
139
140} // namespace juce
141
142/** @}*/
Wraps a pointer to a null-terminated UTF-8 character string, and provides various methods to operate ...
Represents a local file or directory.
Definition: juce_File.h:45
The base class for streams that read data.
Contains static methods for converting JSON-formatted text to and from var objects.
Definition: juce_JSON.h:43
The base class for streams that write data to some kind of destination.
Represents the 'success' or 'failure' of an operation, and holds an associated error message to descr...
Definition: juce_Result.h:61
A simple class for holding temporary references to a string literal or String.
The JUCE String class!
Definition: juce_String.h:43
A variant class, that can be used to hold a range of primitive values.
Definition: juce_Variant.h:46
#define JUCE_API
This macro is added to all JUCE public class declarations.