void NodeRecord::printJson()

in lang/c++/impl/NodeImpl.cc [263:343]


void NodeRecord::printJson(std::ostream &os, size_t depth) const {
    os << "{\n";
    os << indent(++depth) << "\"type\": \"record\",\n";
    printLogicalType(os, logicalType(), depth);
    const Name &name = nameAttribute_.get();
    printName(os, name, depth);

    const auto &aliases = name.aliases();
    if (!aliases.empty()) {
        os << indent(depth) << "\"aliases\": [";
        ++depth;
        for (size_t i = 0; i < aliases.size(); ++i) {
            if (i > 0) {
                os << ',';
            }
            os << '\n'
               << indent(depth) << "\"" << aliases[i] << "\"";
        }
        os << '\n'
           << indent(--depth) << "]\n";
    }

    if (!getDoc().empty()) {
        os << indent(depth) << R"("doc": ")"
           << escape(getDoc()) << "\",\n";
    }

    os << indent(depth) << "\"fields\": [";
    size_t fields = leafAttributes_.size();
    ++depth;
    assert(fieldsAliases_.empty() || (fieldsAliases_.size() == fields));
    assert(fieldsDefaultValues_.empty() || (fieldsDefaultValues_.size() == fields));
    assert(customAttributes_.size() == 0 || customAttributes_.size() == fields);
    for (size_t i = 0; i < fields; ++i) {
        if (i > 0) {
            os << ',';
        }
        os << '\n'
           << indent(depth) << "{\n";
        os << indent(++depth) << R"("name": ")" << leafNameAttributes_.get(i) << "\",\n";
        os << indent(depth) << "\"type\": ";
        leafAttributes_.get(i)->printJson(os, depth);

        if (!fieldsAliases_.empty() && !fieldsAliases_[i].empty()) {
            os << ",\n"
               << indent(depth) << "\"aliases\": [";
            ++depth;
            for (size_t j = 0; j < fieldsAliases_[i].size(); ++j) {
                if (j > 0) {
                    os << ',';
                }
                os << '\n'
                   << indent(depth) << "\"" << fieldsAliases_[i][j] << "\"";
            }
            os << '\n'
               << indent(--depth) << ']';
        }

        // Serialize "default" field:
        if (!fieldsDefaultValues_.empty()) {
            if (!fieldsDefaultValues_[i].isUnion() && fieldsDefaultValues_[i].type() == AVRO_NULL) {
                // No "default" field.
            } else {
                os << ",\n"
                   << indent(depth) << "\"default\": ";
                leafAttributes_.get(i)->printDefaultToJson(fieldsDefaultValues_[i], os,
                                                           depth);
            }
        }

        if (customAttributes_.size() == fields) {
            printCustomAttributes(customAttributes_.get(i), depth, os);
        }

        os << '\n';
        os << indent(--depth) << '}';
    }
    os << '\n'
       << indent(--depth) << "]\n";
    os << indent(--depth) << '}';
}