Jsonifier provides a prettifyJson
function for quickly prettifying JSON data, which now supports two overloads.
The prettifyJson
function comes in two overloads to provide flexibility:
template<jsonifier::prettify_options options = jsonifier::prettify_options{}, jsonifier::concepts::string_t string_type>
auto prettifyJson(string_type&& in) noexcept;
template<jsonifier::prettify_options options = jsonifier::prettify_options{}, jsonifier::concepts::string_t string_type01, jsonifier::concepts::string_t string_type02>
bool prettify(string_type01&& in, string_type02&& out) noexcept;
These overloads allow you to customize prettifying behavior and handle output flexibly.
Here are examples demonstrating the usage of the prettifyJson
function:
#include "jsonifier/Index.hpp"
jsonifier::string buffer = "{\"key\": \"value\"}";
// Prettify JSON data.
auto prettifiedBuffer = jsonifier::prettifyJson(buffer);
#include "jsonifier/Index.hpp"
jsonifier::string buffer = "{\"key\": \"value\"}";
jsonifier::string prettifiedBuffer;
// Prettify JSON data and output to another string.
jsonifier::prettifyJson(buffer, prettifiedBuffer);
These examples demonstrate how to prettifyJson JSON data using the prettifyJson
function, both directly and by outputting to another string.
The prettify_options
struct allows customization of prettifying behavior. Here's the structure of the prettify_options
:
struct prettify_options {
uint64_t indentSize{ 3 };
char indentChar{ ' ' };
};
indentSize
: Sets the size of indentation (default:3
).indentChar
: Specifies the default character to use for indentation (default:
You can specify these options when calling the prettifyJson
function to customize the prettifying behavior.