While both classes share the same, thin client-side API,JsonBstores the data in a decomposed, binary format, whereasJsonstores an exact copy of the RFC 7159 text.
This means thatJsonBis slower to input, but faster to process as it avoids reparsing. Therefore, applications that utilize the structured state of a JSON value should preferJsonB.
It also means that theJsonBstored representation does NOT preserve:
white space,
the order of object keys, or
duplicate object keys.
Note:JsonBis only applicable to PostgreSQL databases (i.e., those created usingDatabaseDialect::POSTGRESQL).
Constructors
JsonB(JsonB const &)
Regular value type, supporting copy, assign, move.
Parameter
Name
Description
JsonB const &
JsonB(JsonB &&)
Regular value type, supporting copy, assign, move.
Parameter
Name
Description
JsonB &&
JsonB()
A null value.
JsonB(std::string)
Construction from a JSON-formatted string.
Note that there is no check here that the argument string is indeed well-formatted. Error detection will be delayed until the value is passed to Spanner.
Parameter
Name
Description
s
std::string
Operators
operator=(JsonB const &)
Regular value type, supporting copy, assign, move.
Parameter
Name
Description
JsonB const &
Returns
Type
Description
JsonB &
operator=(JsonB &&)
Regular value type, supporting copy, assign, move.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe page details the \u003ccode\u003eJsonB\u003c/code\u003e class in the Google Cloud Spanner C++ client library, specifically focusing on versions 2.30.0 through 2.37.0-rc, along with several previous versions.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eJsonB\u003c/code\u003e is a variant of \u003ccode\u003eJson\u003c/code\u003e that stores data in a binary format, making it faster to process but slower to input compared to \u003ccode\u003eJson\u003c/code\u003e, which stores data as an exact copy of the RFC 7159 text.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eJsonB\u003c/code\u003e is best for applications needing the structured state of a JSON value, as it avoids reparsing, but does not preserve whitespace, object key order, or duplicate keys.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eJsonB\u003c/code\u003e class supports copy, assign, and move operations and can be constructed from a JSON-formatted string or as a null value, with error detection on the JSON string being deferred until it is passed to Spanner.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eJsonB\u003c/code\u003e is only applicable to PostgreSQL databases.\u003c/p\u003e\n"]]],[],null,["# Class JsonB (2.30.0)\n\nVersion 2.30.0keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/spanner/latest/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.41.0](/cpp/docs/reference/spanner/2.41.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.40.0](/cpp/docs/reference/spanner/2.40.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.39.0](/cpp/docs/reference/spanner/2.39.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.38.0](/cpp/docs/reference/spanner/2.38.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.37.0](/cpp/docs/reference/spanner/2.37.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.36.0](/cpp/docs/reference/spanner/2.36.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.35.0](/cpp/docs/reference/spanner/2.35.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.34.0](/cpp/docs/reference/spanner/2.34.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.33.0](/cpp/docs/reference/spanner/2.33.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.32.0](/cpp/docs/reference/spanner/2.32.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.31.0](/cpp/docs/reference/spanner/2.31.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.30.0](/cpp/docs/reference/spanner/2.30.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.29.0](/cpp/docs/reference/spanner/2.29.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.28.0](/cpp/docs/reference/spanner/2.28.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.27.0](/cpp/docs/reference/spanner/2.27.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.26.0](/cpp/docs/reference/spanner/2.26.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.25.1](/cpp/docs/reference/spanner/2.25.1/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.24.0](/cpp/docs/reference/spanner/2.24.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.23.0](/cpp/docs/reference/spanner/2.23.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.22.1](/cpp/docs/reference/spanner/2.22.1/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.21.0](/cpp/docs/reference/spanner/2.21.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.20.0](/cpp/docs/reference/spanner/2.20.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.19.0](/cpp/docs/reference/spanner/2.19.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.18.0](/cpp/docs/reference/spanner/2.18.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.17.0](/cpp/docs/reference/spanner/2.17.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.16.0](/cpp/docs/reference/spanner/2.16.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.15.1](/cpp/docs/reference/spanner/2.15.1/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.14.0](/cpp/docs/reference/spanner/2.14.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.13.0](/cpp/docs/reference/spanner/2.13.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.12.0](/cpp/docs/reference/spanner/2.12.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB)\n- [2.11.0](/cpp/docs/reference/spanner/2.11.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB) \n[`JsonB`](/cpp/docs/reference/spanner/2.30.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB) is a variant of [`Json`](/cpp/docs/reference/spanner/2.30.0/classgoogle_1_1cloud_1_1spanner_1_1Json) (see above). \nWhile both classes share the same, thin client-side API, [`JsonB`](/cpp/docs/reference/spanner/2.30.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB) stores the data in a decomposed, binary format, whereas [`Json`](/cpp/docs/reference/spanner/2.30.0/classgoogle_1_1cloud_1_1spanner_1_1Json) stores an exact copy of the RFC 7159 text.\n\nThis means that [`JsonB`](/cpp/docs/reference/spanner/2.30.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB) is slower to input, but faster to process as it avoids reparsing. Therefore, applications that utilize the structured state of a JSON value should prefer [`JsonB`](/cpp/docs/reference/spanner/2.30.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB).\n\nIt also means that the [`JsonB`](/cpp/docs/reference/spanner/2.30.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB) stored representation does NOT preserve:\n\n- white space,\n- the order of object keys, or\n- duplicate object keys.\n\nNote: [`JsonB`](/cpp/docs/reference/spanner/2.30.0/classgoogle_1_1cloud_1_1spanner_1_1JsonB) is only applicable to PostgreSQL databases (i.e., those created using `DatabaseDialect::POSTGRESQL`).\n\nConstructors\n------------\n\n### JsonB(JsonB const \\&)\n\nRegular value type, supporting copy, assign, move.\n\n### JsonB(JsonB \\&\\&)\n\nRegular value type, supporting copy, assign, move.\n\n### JsonB()\n\nA null value.\n\n### JsonB(std::string)\n\nConstruction from a JSON-formatted string. \nNote that there is no check here that the argument string is indeed well-formatted. Error detection will be delayed until the value is passed to Spanner.\n\nOperators\n---------\n\n### operator=(JsonB const \\&)\n\nRegular value type, supporting copy, assign, move.\n\n### operator=(JsonB \\&\\&)\n\nRegular value type, supporting copy, assign, move.\n\n### operator std::string() const \\&\n\nConversion to a JSON-formatted string.\n\n### operator std::string() \\&\\&\n\nConversion to a JSON-formatted string."]]