Skip to content
JsonBlock

ShorthandAdd

JsonData& ShorthandAdd(const std::string shorthand, const char delimiter = '.')
JsonData& ShorthandAdd(const std::string shorthand, const std::string delimiter)

Shorthand function.
A shorthand function is designed to make working with deep, nested json structures easier and faster.

Does the same as Add(), but with a shorthand label.
Furthermore, will it create every path element necessary.

If you, for whatever reason, don't want to use the '.' delimiter, you can specify a custom one. It can even be a string!

Shorthand validity

If the shorthand is invalid, a JsonShorthandInvalidException will be thrown.
The validity of a shorthand depends on the function it is given to. In this case, a shorthand is invalid, if

  • The shorthand is empty ("")
  • The last path segment already exists
  • At least one existing non-last path segment is not of type JSON

Examples:

C++:
JsonBlock myJsonBlock;
myJsonBlock.ShorthandAdd("id.names.firstname").SetStringData("Joseph");
Resulting json:
{
    "id": {
        "names": {
            "firstname": "Joseph"
        }
    }
}
Custom delimiter (C++):
myJsonBlock.ShorthandAdd("id->names->firstname", "->").SetStringData("Joseph");
myJsonBlock.ShorthandAdd("id/names/firstname, '/'").SetStringData("Joseph");