LLVM 20.0.0git
Classes | Namespaces | Functions | Variables
JSON.h File Reference

This file supports working with JSON data. More...

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/raw_ostream.h"
#include <cmath>
#include <map>

Go to the source code of this file.

Classes

class  llvm::json::Object
 An Object is a JSON object, which maps strings to heterogenous JSON values. More...
 
class  llvm::json::Array
 An Array is a JSON array, which contains heterogeneous JSON values. More...
 
class  llvm::json::Value
 A Value is an JSON value of unknown type. More...
 
class  llvm::json::ObjectKey
 ObjectKey is a used to capture keys in Object. More...
 
struct  llvm::json::Object::KV
 
class  llvm::json::Path
 A "cursor" marking a position within a Value. More...
 
class  llvm::json::Path::Root
 The root is the trivial Path to the root value. More...
 
class  llvm::json::ObjectMapper
 Helper for mapping JSON objects onto protocol structs. More...
 
class  llvm::json::ParseError
 
class  llvm::json::OStream
 json::OStream allows writing well-formed JSON without materializing all structures as json::Value ahead of time. More...
 
struct  llvm::format_provider< llvm::json::Value >
 Allow printing json::Value with formatv(). More...
 

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.
 
namespace  llvm::json
 

Functions

bool llvm::json::isUTF8 (llvm::StringRef S, size_t *ErrOffset=nullptr)
 Returns true if S is valid UTF-8, which is required for use as JSON.
 
std::string llvm::json::fixUTF8 (llvm::StringRef S)
 Replaces invalid UTF-8 sequences in S with the replacement character (U+FFFD).
 
template<typename T >
Value llvm::json::toJSON (const std::optional< T > &Opt)
 
bool llvm::json::operator== (const Object &LHS, const Object &RHS)
 
bool llvm::json::operator!= (const Object &LHS, const Object &RHS)
 
bool llvm::json::operator!= (const Array &L, const Array &R)
 
bool llvm::json::operator== (const Value &, const Value &)
 
bool llvm::json::operator!= (const Value &L, const Value &R)
 
bool llvm::json::operator== (const Array &L, const Array &R)
 
bool llvm::json::operator== (const ObjectKey &L, const ObjectKey &R)
 
bool llvm::json::operator!= (const ObjectKey &L, const ObjectKey &R)
 
bool llvm::json::operator< (const ObjectKey &L, const ObjectKey &R)
 
std::vector< const Object::value_type * > llvm::json::sortedElements (const Object &O)
 
bool llvm::json::fromJSON (const Value &E, std::string &Out, Path P)
 
bool llvm::json::fromJSON (const Value &E, int &Out, Path P)
 
bool llvm::json::fromJSON (const Value &E, int64_t &Out, Path P)
 
bool llvm::json::fromJSON (const Value &E, double &Out, Path P)
 
bool llvm::json::fromJSON (const Value &E, bool &Out, Path P)
 
bool llvm::json::fromJSON (const Value &E, uint64_t &Out, Path P)
 
bool llvm::json::fromJSON (const Value &E, std::nullptr_t &Out, Path P)
 
template<typename T >
bool llvm::json::fromJSON (const Value &E, std::optional< T > &Out, Path P)
 
template<typename T >
bool llvm::json::fromJSON (const Value &E, std::vector< T > &Out, Path P)
 
template<typename T >
bool llvm::json::fromJSON (const Value &E, std::map< std::string, T > &Out, Path P)
 
llvm::Expected< Value > llvm::json::parse (llvm::StringRef JSON)
 Parses the provided JSON source, or returns a ParseError.
 
template<typename T >
Expected< Tllvm::json::parse (const llvm::StringRef &JSON, const char *RootName="")
 Version of parse() that converts the parsed value to the type T.
 
llvm::raw_ostreamllvm::json::operator<< (llvm::raw_ostream &OS, const Value &V)
 Serializes this Value to JSON, writing it to the provided stream.
 

Variables

template<typename T >
constexpr bool llvm::json::is_uint_64_bit_v
 

Detailed Description

This file supports working with JSON data.

It comprises:

Typically, JSON data would be read from an external source, parsed into a Value, and then converted into some native data structure before doing real work on it. (And vice versa when writing).

Other serialization mechanisms you may consider:

Definition in file JSON.h.