|
LLVM_ABI 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.
|
LLVM_ABI 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) |
LLVM_ABI 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) |
LLVM_ABI bool | llvm::json::operator== (const Value &L, const Value &R) |
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) |
LLVM_ABI 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, unsigned int &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_ABI llvm::Expected< Value > | llvm::json::parse (llvm::StringRef JSON) |
| Parses the provided JSON source, or returns a ParseError.
|
template<typename T> |
Expected< T > | llvm::json::parse (const llvm::StringRef &JSON, const char *RootName="") |
| Version of parse() that converts the parsed value to the type T.
|
llvm::raw_ostream & | llvm::json::operator<< (llvm::raw_ostream &OS, const Value &V) |
| Serializes this Value to JSON, writing it to the provided stream.
|
This file supports working with JSON data.
It comprises:
- classes which hold dynamically-typed parsed JSON structures These are value types that can be composed, inspected, and modified. See json::Value, and the related types json::Object and json::Array.
- functions to parse JSON text into Values, and to serialize Values to text. See parse(), operator<<, and format_provider.
- a convention and helpers for mapping between json::Value and user-defined types. See fromJSON(), ObjectMapper, and the class comment on Value.
- an output API json::OStream which can emit JSON without materializing all structures as json::Value.
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:
- YAML is also text-based, and more human-readable than JSON. It's a more complex format and data model, and YAML parsers aren't ubiquitous. YAMLParser.h is a streaming parser suitable for parsing large documents (including JSON, as YAML is a superset). It can be awkward to use directly. YAML I/O (YAMLTraits.h) provides data mapping that is more declarative than the toJSON/fromJSON conventions here.
- LLVM bitstream is a space- and CPU- efficient binary format. Typically it encodes LLVM IR ("bitcode"), but it can be a container for other data. Low-level reader/writer libraries are in Bitstream/Bitstream*.h
Definition in file JSON.h.