This function is called by the public member function dump and organizes the serialization internally. The indentation level is propagated as additional parameter. In case of arrays and objects, the function is called recursively.
16688 {
16689 switch (val.m_type)
16690 {
16692 {
16693 if (val.m_value.object->empty())
16694 {
16695 o->write_characters("{}", 2);
16696 return;
16697 }
16698
16699 if (pretty_print)
16700 {
16701 o->write_characters("{\n", 2);
16702
16703 const auto new_indent = current_indent + indent_step;
16704
16705 if (JSON_HEDLEY_UNLIKELY(
indent_string.size() < new_indent))
16706 {
16708 }
16709
16710
16711 auto i = val.m_value.object->cbegin();
16712
16713 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
16714 {
16716 o->write_character('\"');
16717 dump_escaped(i->first, ensure_ascii);
16718 o->write_characters("\": ", 3);
16719 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
16720 o->write_characters(",\n", 2);
16721 }
16722
16723
16724 JSON_ASSERT(i != val.m_value.object->cend());
16725 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
16727 o->write_character('\"');
16728 dump_escaped(i->first, ensure_ascii);
16729 o->write_characters("\": ", 3);
16730 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
16731 o->write_character('\n');
16732 o->write_characters(
indent_string.c_str(), current_indent);
16733 o->write_character('}');
16734 }
16735
16736 else
16737 {
16738 o->write_character('{');
16739
16740 auto i = val.m_value.object->cbegin();
16741
16742 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
16743 {
16744 o->write_character('\"');
16745 dump_escaped(i->first, ensure_ascii);
16746 o->write_characters("\":", 2);
16747 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
16748 o->write_character(',');
16749 }
16750
16751
16752 JSON_ASSERT(i != val.m_value.object->cend());
16753 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
16754 o->write_character('\"');
16755 dump_escaped(i->first, ensure_ascii);
16756 o->write_characters("\":", 2);
16757 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
16758 o->write_character('}');
16759 }
16760
16761 return;
16762 }
16763
16765 {
16766 if (val.m_value.array->empty())
16767 {
16768 o->write_characters("[]", 2);
16769 return;
16770 }
16771
16772 if (pretty_print)
16773 {
16774 o->write_characters("[\n", 2);
16775
16776 const auto new_indent = current_indent + indent_step;
16777
16778 if (JSON_HEDLEY_UNLIKELY(
indent_string.size() < new_indent))
16779 {
16781 }
16782
16783
16784 for (auto i = val.m_value.array->cbegin();
16785 i != val.m_value.array->cend() - 1; ++i)
16786 {
16788 dump(*i,
true, ensure_ascii, indent_step, new_indent);
16789 o->write_characters(",\n", 2);
16790 }
16791
16792
16793 JSON_ASSERT(!val.m_value.array->empty());
16795 dump(val.m_value.array->back(),
true, ensure_ascii, indent_step, new_indent);
16796 o->write_character('\n');
16797 o->write_characters(
indent_string.c_str(), current_indent);
16798 o->write_character(']');
16799 }
16800
16801 else
16802 {
16803 o->write_character('[');
16804
16805
16806 for (auto i = val.m_value.array->cbegin();
16807 i != val.m_value.array->cend() - 1; ++i)
16808 {
16809 dump(*i,
false, ensure_ascii, indent_step, current_indent);
16810 o->write_character(',');
16811 }
16812
16813
16814 JSON_ASSERT(!val.m_value.array->empty());
16815 dump(val.m_value.array->back(),
false, ensure_ascii, indent_step, current_indent);
16816 o->write_character(']');
16817 }
16818
16819 return;
16820 }
16821
16823 {
16824 o->write_character('\"');
16825 dump_escaped(*val.m_value.string, ensure_ascii);
16826 o->write_character('\"');
16827 return;
16828 }
16829
16831 {
16832 if (pretty_print)
16833 {
16834 o->write_characters("{\n", 2);
16835
16836 const auto new_indent = current_indent + indent_step;
16837
16838 if (JSON_HEDLEY_UNLIKELY(
indent_string.size() < new_indent))
16839 {
16841 }
16842
16844 o->write_characters("\"bytes\": [", 10);
16845
16846 if (!val.m_value.binary->empty())
16847 {
16848 for (auto i = val.m_value.binary->cbegin();
16849 i != val.m_value.binary->cend() - 1; ++i)
16850 {
16851 dump_integer(*i);
16852 o->write_characters(", ", 2);
16853 }
16854
16855 dump_integer(val.m_value.binary->back());
16856 }
16857
16858 o->write_characters("],\n", 3);
16860 o->write_characters("\"subtype\": ", 11);
16861
16862 if (val.m_value.binary->has_subtype())
16863 {
16864 dump_integer(val.m_value.binary->subtype());
16865 }
16866
16867 else
16868 {
16869 o->write_characters("null", 4);
16870 }
16871
16872 o->write_character('\n');
16873 o->write_characters(
indent_string.c_str(), current_indent);
16874 o->write_character('}');
16875 }
16876
16877 else
16878 {
16879 o->write_characters("{\"bytes\":[", 10);
16880
16881 if (!val.m_value.binary->empty())
16882 {
16883 for (auto i = val.m_value.binary->cbegin();
16884 i != val.m_value.binary->cend() - 1; ++i)
16885 {
16886 dump_integer(*i);
16887 o->write_character(',');
16888 }
16889
16890 dump_integer(val.m_value.binary->back());
16891 }
16892
16893 o->write_characters("],\"subtype\":", 12);
16894
16895 if (val.m_value.binary->has_subtype())
16896 {
16897 dump_integer(val.m_value.binary->subtype());
16898 o->write_character('}');
16899 }
16900
16901 else
16902 {
16903 o->write_characters("null}", 5);
16904 }
16905 }
16906
16907 return;
16908 }
16909
16911 {
16912 if (val.m_value.boolean)
16913 {
16914 o->write_characters("true", 4);
16915 }
16916
16917 else
16918 {
16919 o->write_characters("false", 5);
16920 }
16921
16922 return;
16923 }
16924
16926 {
16927 dump_integer(val.m_value.number_integer);
16928 return;
16929 }
16930
16932 {
16933 dump_integer(val.m_value.number_unsigned);
16934 return;
16935 }
16936
16938 {
16939 dump_float(val.m_value.number_float);
16940 return;
16941 }
16942
16944 {
16945 o->write_characters("<discarded>", 11);
16946 return;
16947 }
16948
16950 {
16951 o->write_characters("null", 4);
16952 return;
16953 }
16954
16955 default:
16956 JSON_ASSERT(false);
16957 }
16958 }
void dump(const BasicJsonType &val, const bool pretty_print, const bool ensure_ascii, const unsigned int indent_step, const unsigned int current_indent=0)
internal implementation of the serialization function
string_t indent_string
the indentation string
@ number_integer
number value (signed integer)
@ discarded
discarded by the parser callback function
@ binary
binary array (ordered collection of bytes)
@ object
object (unordered set of name/value pairs)
@ number_float
number value (floating-point)
@ number_unsigned
number value (unsigned integer)
@ array
array (ordered collection of values)