simdjson  3.11.0
Ridiculously Fast JSON
simdjson Namespace Reference

The top level simdjson namespace, containing everything the library provides. More...

Namespaces

 arm64
 Implementation for NEON (ARMv8).
 
 dom
 A DOM API on top of the simdjson parser.
 
 fallback
 Fallback implementation (runs on any machine).
 
 haswell
 Implementation for Haswell (Intel AVX2).
 
 icelake
 Implementation for Icelake (Intel AVX512).
 
 lasx
 Implementation for LASX.
 
 lsx
 Implementation for LSX.
 
 ppc64
 Implementation for ALTIVEC (PPC64).
 
 westmere
 Implementation for Westmere (Intel SSE4.2).
 

Classes

struct  simdjson_result< dom::array >
 The result of a JSON conversion that may fail. More...
 
struct  simdjson_result< dom::document_stream >
 
struct  simdjson_result< dom::element >
 The result of a JSON navigation that may fail. More...
 
struct  simdjson_result< dom::object >
 The result of a JSON conversion that may fail. More...
 
struct  simdjson_error
 Exception thrown when an exception-supporting simdjson method is called. More...
 
struct  simdjson_result
 The result of a simdjson operation that could fail. More...
 
struct  simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::array >
 
struct  simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::array_iterator >
 
struct  simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::document >
 
struct  simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::document_reference >
 
struct  simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::document_stream >
 
struct  simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::field >
 
struct  simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::json_iterator >
 
struct  simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::json_type >
 
struct  simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::object >
 
struct  simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::object_iterator >
 
struct  simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::parser >
 
struct  simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string >
 
struct  simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::token_iterator >
 
struct  simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::value >
 
struct  simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::value_iterator >
 
class  implementation
 An implementation of simdjson for a particular CPU architecture. More...
 
struct  padded_string
 String with extra allocation for ease of use with parser::parse() More...
 
class  padded_string_view
 User-provided string that promises it has extra padded bytes at the end for use with parser::parse(). More...
 

Typedefs

using ErrorValues = error_code
 

Enumerations

enum  error_code {
  SUCCESS = 0 , CAPACITY , MEMALLOC , TAPE_ERROR ,
  DEPTH_ERROR , STRING_ERROR , T_ATOM_ERROR , F_ATOM_ERROR ,
  N_ATOM_ERROR , NUMBER_ERROR , BIGINT_ERROR , UTF8_ERROR ,
  UNINITIALIZED , EMPTY , UNESCAPED_CHARS , UNCLOSED_STRING ,
  UNSUPPORTED_ARCHITECTURE , INCORRECT_TYPE , NUMBER_OUT_OF_RANGE , INDEX_OUT_OF_BOUNDS ,
  NO_SUCH_FIELD , IO_ERROR , INVALID_JSON_POINTER , INVALID_URI_FRAGMENT ,
  UNEXPECTED_ERROR , PARSER_IN_USE , OUT_OF_ORDER_ITERATION , INSUFFICIENT_PADDING ,
  INCOMPLETE_ARRAY_OR_OBJECT , SCALAR_DOCUMENT_AS_VALUE , OUT_OF_BOUNDS , TRAILING_CONTENT ,
  NUM_ERROR_CODES
}
 All possible errors returned by simdjson. More...
 
enum class  stage1_mode { regular , streaming_partial , streaming_final }
 This enum is used with the dom_parser_implementation::stage1 function. More...
 
enum  { SIMDJSON_VERSION_MAJOR = 3 , SIMDJSON_VERSION_MINOR = 11 , SIMDJSON_VERSION_REVISION = 0 }
 

Functions

const implementationbuiltin_implementation ()
 Function which returns a pointer to an implementation matching the "builtin" implementation. More...
 
template<class T >
std::string to_string (T x)
 Converts JSON to a string. More...
 
template<class T >
std::string to_string (simdjson_result< T > x)
 
template<class T >
std::string minify (T x)
 Minifies a JSON element or document, printing the smallest possible valid JSON. More...
 
template<class T >
std::string minify (simdjson_result< T > x)
 
template<class T >
std::string prettify (T x)
 Prettifies a JSON element or document, printing the valid JSON with indentation. More...
 
template<class T >
std::string prettify (simdjson_result< T > x)
 
const char * error_message (error_code error) noexcept
 It is the convention throughout the code that the macro SIMDJSON_DEVELOPMENT_CHECKS determines whether we check for OUT_OF_ORDER_ITERATION. More...
 
const std::string error_message (int error) noexcept
 
std::ostream & operator<< (std::ostream &out, error_code error) noexcept
 Write the error message to the output stream.
 
template<typename T >
std::ostream & operator<< (std::ostream &out, simdjson_result< T > value)
 
std::string_view trim (const std::string_view str) noexcept
 
simdjson_result< std::string_view > to_json_string (SIMDJSON_IMPLEMENTATION::ondemand::document &x) noexcept
 Create a string-view instance out of a document instance. More...
 
simdjson_result< std::string_view > to_json_string (SIMDJSON_IMPLEMENTATION::ondemand::document_reference &x) noexcept
 
simdjson_result< std::string_view > to_json_string (SIMDJSON_IMPLEMENTATION::ondemand::value &x) noexcept
 Create a string-view instance out of a value instance. More...
 
simdjson_result< std::string_view > to_json_string (SIMDJSON_IMPLEMENTATION::ondemand::object &x) noexcept
 Create a string-view instance out of an object instance. More...
 
simdjson_result< std::string_view > to_json_string (SIMDJSON_IMPLEMENTATION::ondemand::array &x) noexcept
 Create a string-view instance out of an array instance. More...
 
simdjson_result< std::string_view > to_json_string (simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::document > x)
 
simdjson_result< std::string_view > to_json_string (simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::document_reference > x)
 
simdjson_result< std::string_view > to_json_string (simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::value > x)
 
simdjson_result< std::string_view > to_json_string (simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::object > x)
 
simdjson_result< std::string_view > to_json_string (simdjson_result< SIMDJSON_IMPLEMENTATION::ondemand::array > x)
 
simdjson_warn_unused bool validate_utf8 (const char *buf, size_t len) noexcept
 Validate the UTF-8 string. More...
 
simdjson_inline simdjson_warn_unused bool validate_utf8 (const std::string_view sv) noexcept
 Validate the UTF-8 string. More...
 
simdjson_inline simdjson_warn_unused bool validate_utf8 (const std::string &s) noexcept
 Validate the UTF-8 string. More...
 
SIMDJSON_DLLIMPORTEXPORT const internal::available_implementation_list & get_available_implementations ()
 The list of available implementations compiled into simdjson.
 
SIMDJSON_DLLIMPORTEXPORT internal::atomic_ptr< const implementation > & get_active_implementation ()
 The active implementation. More...
 
bool is_streaming (stage1_mode mode)
 Returns true if mode == streaming_partial or mode == streaming_final.
 
padded_string get_corpus (const char *path)
 
std::string json_path_to_pointer_conversion (std::string_view json_path)
 Converts JSONPath to JSON Pointer. More...
 
simdjson_warn_unused error_code minify (const char *buf, size_t len, char *dst, size_t &dst_len) noexcept
 Minify the input string assuming that it represents a JSON string, does not parse or validate. More...
 
std::ostream & operator<< (std::ostream &out, const padded_string &s)
 Send padded_string instance to an output stream. More...
 
std::ostream & operator<< (std::ostream &out, simdjson_result< padded_string > &s) noexcept(false)
 Send padded_string instance to an output stream. More...
 
std::ostream & operator<< (std::ostream &out, simdjson_result< padded_string_view > &s) noexcept(false)
 Send padded_string instance to an output stream. More...
 
padded_string_view pad (std::string &s) noexcept
 Create a padded_string_view from a string. More...
 

Variables

constexpr SIMDJSON_PUSH_DISABLE_UNUSED_WARNINGS size_t SIMDJSON_MAXSIZE_BYTES = 0xFFFFFFFF
 The maximum document size supported by simdjson.
 
constexpr size_t SIMDJSON_PADDING = 64
 The amount of padding needed in a buffer to parse JSON. More...
 
constexpr size_t DEFAULT_MAX_DEPTH = 1024
 By default, simdjson supports this many nested objects and arrays. More...
 

Detailed Description

The top level simdjson namespace, containing everything the library provides.

We want to support argument-dependent lookup (ADL).

Hence we should define operator<< in the namespace where the argument (here value, object, etc.) resides. Credit: @madhur4127 See https://github.com/simdjson/simdjson/issues/1768

Typedef Documentation

◆ ErrorValues

Deprecated:
This is an alias and will be removed, use error_code instead

Definition at line 308 of file error.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SIMDJSON_VERSION_MAJOR 

The major version (MAJOR.minor.revision) of simdjson being used.

SIMDJSON_VERSION_MINOR 

The minor version (major.MINOR.revision) of simdjson being used.

SIMDJSON_VERSION_REVISION 

The revision (major.minor.REVISION) of simdjson being used.

Definition at line 10 of file simdjson_version.h.

◆ error_code

All possible errors returned by simdjson.

These error codes are subject to change and not all simdjson kernel returns the same error code given the same input: it is not well defined which error a given input should produce.

Only SUCCESS evaluates to false as a Boolean. All other error codes will evaluate to true as a Boolean.

Enumerator
SUCCESS 

No error.

CAPACITY 

This parser can't support a document that big.

MEMALLOC 

Error allocating memory, most likely out of memory.

TAPE_ERROR 

Something went wrong, this is a generic error.

DEPTH_ERROR 

Your document exceeds the user-specified depth limitation.

STRING_ERROR 

Problem while parsing a string.

T_ATOM_ERROR 

Problem while parsing an atom starting with the letter 't'.

F_ATOM_ERROR 

Problem while parsing an atom starting with the letter 'f'.

N_ATOM_ERROR 

Problem while parsing an atom starting with the letter 'n'.

NUMBER_ERROR 

Problem while parsing a number.

BIGINT_ERROR 

The integer value exceeds 64 bits.

UTF8_ERROR 

the input is not valid UTF-8

UNINITIALIZED 

unknown error, or uninitialized document

EMPTY 

no structural element found

UNESCAPED_CHARS 

found unescaped characters in a string.

UNCLOSED_STRING 

missing quote at the end

UNSUPPORTED_ARCHITECTURE 

unsupported architecture

INCORRECT_TYPE 

JSON element has a different type than user expected.

NUMBER_OUT_OF_RANGE 

JSON number does not fit in 64 bits.

INDEX_OUT_OF_BOUNDS 

JSON array index too large.

NO_SUCH_FIELD 

JSON field not found in object.

IO_ERROR 

Error reading a file.

INVALID_JSON_POINTER 

Invalid JSON pointer syntax.

INVALID_URI_FRAGMENT 

Invalid URI fragment.

UNEXPECTED_ERROR 

indicative of a bug in simdjson

PARSER_IN_USE 

parser is already in use.

OUT_OF_ORDER_ITERATION 

tried to iterate an array or object out of order (checked when SIMDJSON_DEVELOPMENT_CHECKS=1)

INSUFFICIENT_PADDING 

The JSON doesn't have enough padding for simdjson to safely parse it.

INCOMPLETE_ARRAY_OR_OBJECT 

The document ends early.

SCALAR_DOCUMENT_AS_VALUE 

A scalar document is treated as a value.

OUT_OF_BOUNDS 

Attempted to access location outside of document.

TRAILING_CONTENT 

Unexpected trailing content in the JSON input.

Definition at line 19 of file error.h.

◆ stage1_mode

enum simdjson::stage1_mode
strong

This enum is used with the dom_parser_implementation::stage1 function.

1) The regular mode expects a fully formed JSON document. 2) The streaming_partial mode expects a possibly truncated input within a stream on JSON documents. 3) The stream_final mode allows us to truncate final unterminated strings. It is useful in conjunction with streaming_partial.

Definition at line 22 of file dom_parser_implementation.h.

Function Documentation

◆ builtin_implementation()

const implementation* simdjson::builtin_implementation ( )

Function which returns a pointer to an implementation matching the "builtin" implementation.

The builtin implementation is the best statically linked simdjson implementation that can be used by the compiling program. If you compile with g++ -march=haswell, this will return the haswell implementation. It is handy to be able to check what builtin was used: builtin_implementation()->name().

◆ error_message() [1/2]

const char * simdjson::error_message ( error_code  error)
inlinenoexcept

It is the convention throughout the code that the macro SIMDJSON_DEVELOPMENT_CHECKS determines whether we check for OUT_OF_ORDER_ITERATION.

The logic behind it is that these errors only occurs when the code that was written while breaking some simdjson::ondemand requirement. They should not occur in released code after these issues were fixed. Get the error message for the given error code.

dom::parser parser; dom::element doc; auto error = parser.parse("foo",3).get(doc); if (error) { printf("Error: %s\n", error_message(error)); }

Returns
The error message.

Definition at line 20 of file error-inl.h.

◆ error_message() [2/2]

const std::string simdjson::error_message ( int  error)
inlinenoexcept
Deprecated:
Error codes should be stored and returned as error_code, use error_message() instead.

Definition at line 27 of file error-inl.h.

◆ get_active_implementation()

SIMDJSON_DLLIMPORTEXPORT internal::atomic_ptr<const implementation>& simdjson::get_active_implementation ( )

The active implementation.

Automatically initialized on first use to the most advanced implementation supported by this hardware.

◆ json_path_to_pointer_conversion()

std::string simdjson::json_path_to_pointer_conversion ( std::string_view  json_path)
inline

Converts JSONPath to JSON Pointer.

Parameters
json_pathThe JSONPath string to be converted.
Returns
A string containing the equivalent JSON Pointer.

Definition at line 13 of file jsonpathutil.h.

◆ minify() [1/2]

simdjson_warn_unused error_code simdjson::minify ( const char *  buf,
size_t  len,
char *  dst,
size_t &  dst_len 
)
noexcept

Minify the input string assuming that it represents a JSON string, does not parse or validate.

This function is much faster than parsing a JSON string and then writing a minified version of it. However, it does not validate the input. It will merely return an error in simple cases (e.g., if there is a string that was never terminated).

Parameters
bufthe json document to minify.
lenthe length of the json document.
dstthe buffer to write the minified document to. MUST be allocated up to len bytes.
dst_lenthe number of bytes written. Output only.
Returns
the error code, or SUCCESS if there was no error.

◆ minify() [2/2]

template<class T >
std::string simdjson::minify ( x)

Minifies a JSON element or document, printing the smallest possible valid JSON.

dom::parser parser; element doc = parser.parse(" [ 1 , 2 , 3 ] "_padded); cout << minify(doc) << endl; // prints [1,2,3]

Definition at line 212 of file serialization.h.

◆ operator<<() [1/3]

std::ostream& simdjson::operator<< ( std::ostream &  out,
const padded_string s 
)
inline

Send padded_string instance to an output stream.

Parameters
outThe output stream.
sThe padded_string instance.
Exceptions
ifthere is an error with the underlying output stream. simdjson itself will not throw.

Definition at line 146 of file padded_string.h.

◆ operator<<() [2/3]

std::ostream& simdjson::operator<< ( std::ostream &  out,
simdjson_result< padded_string > &  s 
)
inlinenoexcept

Send padded_string instance to an output stream.

Parameters
outThe output stream.
sThe padded_string instance.
Exceptions
simdjson_errorif the result being printed has an error. If there is an error with the underlying output stream, that error will be propagated (simdjson_error will not be thrown).

Definition at line 158 of file padded_string.h.

◆ operator<<() [3/3]

std::ostream & simdjson::operator<< ( std::ostream &  out,
simdjson_result< padded_string_view > &  s 
)
inlinenoexcept

Send padded_string instance to an output stream.

Parameters
outThe output stream.
sThe padded_string_view.
Exceptions
simdjson_errorif the result being printed has an error. If there is an error with the underlying output stream, that error will be propagated (simdjson_error will not be thrown).

Definition at line 53 of file padded_string_view-inl.h.

◆ pad()

padded_string_view simdjson::pad ( std::string &  s)
inlinenoexcept

Create a padded_string_view from a string.

The string will be padded with SIMDJSON_PADDING space characters. The resulting padded_string_view will have a length equal to the original string.

Parameters
sThe string.
Returns
The padded string.

Definition at line 56 of file padded_string_view-inl.h.

◆ prettify()

template<class T >
std::string simdjson::prettify ( x)

Prettifies a JSON element or document, printing the valid JSON with indentation.

dom::parser parser; element doc = parser.parse(" [ 1 , 2 , 3 ] "_padded);

// Prints: // { // [ // 1, // 2, // 3 // ] // } cout << prettify(doc) << endl;

Definition at line 242 of file serialization.h.

◆ to_json_string() [1/4]

simdjson_result< std::string_view > simdjson::to_json_string ( SIMDJSON_IMPLEMENTATION::ondemand::array x)
inlinenoexcept

Create a string-view instance out of an array instance.

The string-view instance contains JSON text that is suitable to be parsed as JSON again. It does not validate the content.

Definition at line 80 of file serialization-inl.h.

◆ to_json_string() [2/4]

simdjson_result< std::string_view > simdjson::to_json_string ( SIMDJSON_IMPLEMENTATION::ondemand::document x)
inlinenoexcept

Create a string-view instance out of a document instance.

The string-view instance contains JSON text that is suitable to be parsed as JSON again. It does not validate the content.

Definition at line 27 of file serialization-inl.h.

◆ to_json_string() [3/4]

simdjson_result< std::string_view > simdjson::to_json_string ( SIMDJSON_IMPLEMENTATION::ondemand::object x)
inlinenoexcept

Create a string-view instance out of an object instance.

The string-view instance contains JSON text that is suitable to be parsed as JSON again. It does not validate the content.

Definition at line 73 of file serialization-inl.h.

◆ to_json_string() [4/4]

simdjson_result< std::string_view > simdjson::to_json_string ( SIMDJSON_IMPLEMENTATION::ondemand::value x)
inlinenoexcept

Create a string-view instance out of a value instance.

The string-view instance contains JSON text that is suitable to be parsed as JSON again. The value must not have been accessed previously. It does not validate the content.

If we somehow receive a value that has already been consumed, then the following code could be in trouble. E.g., we create an array as needed, but if an array was already created, then it could be bad.

Definition at line 41 of file serialization-inl.h.

◆ to_string()

template<class T >
std::string simdjson::to_string ( x)

Converts JSON to a string.

dom::parser parser; element doc = parser.parse(" [ 1 , 2 , 3 ] "_padded); cout << to_string(doc) << endl; // prints [1,2,3]

Definition at line 186 of file serialization.h.

◆ validate_utf8() [1/3]

simdjson_warn_unused bool simdjson::validate_utf8 ( const char *  buf,
size_t  len 
)
noexcept

Validate the UTF-8 string.

Parameters
bufthe string to validate.
lenthe length of the string in bytes.
Returns
true if the string is valid UTF-8.

◆ validate_utf8() [2/3]

simdjson_inline simdjson_warn_unused bool simdjson::validate_utf8 ( const std::string &  s)
noexcept

Validate the UTF-8 string.

Parameters
pthe string to validate.
Returns
true if the string is valid UTF-8.

Definition at line 35 of file implementation.h.

◆ validate_utf8() [3/3]

simdjson_inline simdjson_warn_unused bool simdjson::validate_utf8 ( const std::string_view  sv)
noexcept

Validate the UTF-8 string.

Parameters
svthe string_view to validate.
Returns
true if the string is valid UTF-8.

Definition at line 25 of file implementation.h.

Variable Documentation

◆ DEFAULT_MAX_DEPTH

constexpr size_t simdjson::DEFAULT_MAX_DEPTH = 1024
constexpr

By default, simdjson supports this many nested objects and arrays.

This is the default for parser::max_depth().

Definition at line 39 of file base.h.

◆ SIMDJSON_PADDING

constexpr size_t simdjson::SIMDJSON_PADDING = 64
constexpr

The amount of padding needed in a buffer to parse JSON.

The input buf should be readable up to buf + SIMDJSON_PADDING this is a stopgap; there should be a better description of the main loop and its behavior that abstracts over this See https://github.com/simdjson/simdjson/issues/174

Definition at line 32 of file base.h.