From caedcc6cb5626d540e015889536cc33b3fe58734 Mon Sep 17 00:00:00 2001 From: john30 Date: Wed, 26 Dec 2018 15:27:47 +0100 Subject: [PATCH] Revert "remove newline from JSON output" This reverts commit d3e496ef6b190ee8868239b4cc8d3f1eb38c02f0. --- src/lib/ebus/data.cpp | 4 ++-- src/lib/ebus/message.cpp | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/lib/ebus/data.cpp b/src/lib/ebus/data.cpp index cdc269f3..3f47def2 100755 --- a/src/lib/ebus/data.cpp +++ b/src/lib/ebus/data.cpp @@ -463,7 +463,7 @@ void SingleDataField::dumpPrefix(bool prependFieldSeparator, bool asJson, ostrea if (prependFieldSeparator) { *output << FIELD_SEPARATOR; } - *output << " {"; + *output << "\n {"; appendJson(false, "name", m_name, true, output); } else { dumpString(prependFieldSeparator, m_name, output); @@ -538,7 +538,7 @@ result_t SingleDataField::read(const SymbolString& data, size_t offset, *output << ","; } if (fieldIndex < 0 && !shortFormat) { - *output << " "; + *output << "\n "; } if (outputIndex >= 0 || m_name.empty() || !(outputFormat & OF_NAMES)) { if (fieldIndex < 0) { diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index b543ca05..5bb97027 100755 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -937,7 +937,7 @@ void Message::decodeJson(bool leadingSeparator, bool appendDirection, bool addRa if (leadingSeparator) { *output << ","; } - *output << " \"" << getName(); + *output << "\n \"" << getName(); if (appendDirection) { if (isPassive()) { *output << "-u"; @@ -947,18 +947,18 @@ void Message::decodeJson(bool leadingSeparator, bool appendDirection, bool addRa } bool withDefinition = (outputFormat & OF_DEFINTION) != 0; *output << "\": {" - << " \"name\": \"" << getName() << "\"" - << ", \"passive\": " << (isPassive() ? "true" : "false") - << ", \"write\": " << (isWrite() ? "true" : "false") - << ", \"lastup\": " << setw(0) << dec << m_lastUpdateTime; + << "\n \"name\": \"" << getName() << "\"" + << ",\n \"passive\": " << (isPassive() ? "true" : "false") + << ",\n \"write\": " << (isWrite() ? "true" : "false") + << ",\n \"lastup\": " << setw(0) << dec << m_lastUpdateTime; bool hasData = getLastUpdateTime() != 0; if (hasData || withDefinition) { if (withDefinition && m_srcAddress != SYN) { - *output << ", \"qq\": " << dec << static_cast(m_srcAddress); + *output << ",\n \"qq\": " << dec << static_cast(m_srcAddress); } - *output << ", \"zz\": " << dec << static_cast(m_dstAddress); + *output << ",\n \"zz\": " << dec << static_cast(m_dstAddress); if (withDefinition) { - *output << ", \"id\": [" << dec; + *output << ",\n \"id\": [" << dec; for (auto it = m_id.begin(); it < m_id.end(); it++) { if (it > m_id.begin()) { *output << ", "; @@ -975,24 +975,24 @@ void Message::decodeJson(bool leadingSeparator, bool appendDirection, bool addRa *output << dec; } size_t pos = (size_t)output->tellp(); - *output << ", \"fields\": {"; + *output << ",\n \"fields\": {"; result_t dret = decodeLastData(false, nullptr, -1, outputFormat, output); if (dret == RESULT_OK) { - *output << "}"; + *output << "\n }"; } else { string prefix = output->str().substr(0, pos); output->str(""); output->clear(); // remove written fields - *output << prefix << ", \"decodeerror\": \"" << getResultCode(dret) << "\""; + *output << prefix << ",\n \"decodeerror\": \"" << getResultCode(dret) << "\""; } } if (withDefinition) { - *output << ", \"fielddefs\": ["; + *output << ",\n \"fielddefs\": ["; m_data->dump(false, true, output); - *output << "]"; + *output << "\n ]"; } } - *output << "}"; + *output << "\n }"; } @@ -2670,7 +2670,7 @@ bool MessageMap::decodeCircuit(const string& circuit, OutputFormat outputFormat, return false; } if (outputFormat & OF_JSON) { - *output << " \"name\": \"" << it->second->getName() << "\""; + *output << "\n \"name\": \"" << it->second->getName() << "\""; } else { *output << it->second->getName() << "="; }