#ifndef INCLUDE_V8_JSON_H_
#define INCLUDE_V8_JSON_H_
#include <optional>
#include "v8-local-handle.h"
#include "v8-message.h"
#include "v8config.h"
namespace v8 {
class Context;
class Value;
class String;
* A JSON Parser and Stringifier.
*/
class V8_EXPORT JSVM_EXPORT JSON {
public:
* Tries to parse the string |json_string| and returns it as value if
* successful.
*
* \param the context in which to parse and create the value.
* \param json_string The string to parse.
* \param origin Optional script origin to use for error reporting.
* If not provided, error reporting will use default origin options
* or attempt to infer origin from the current stack.
* \return The corresponding value if successfully parsed.
*/
static V8_WARN_UNUSED_RESULT MaybeLocal<Value> Parse(
Local<Context> context, Local<String> json_string,
std::optional<ScriptOrigin> origin = std::nullopt);
* Tries to stringify the JSON-serializable object |json_object| and returns
* it as string if successful.
*
* \param json_object The JSON-serializable object to stringify.
* \return The corresponding string if successfully stringified.
*/
static V8_WARN_UNUSED_RESULT MaybeLocal<String> Stringify(
Local<Context> context, Local<Value> json_object,
Local<String> gap = Local<String>());
};
}
#endif