From d3e496ef6b190ee8868239b4cc8d3f1eb38c02f0 Mon Sep 17 00:00:00 2001 From: john30 Date: Tue, 25 Dec 2018 14:11:33 +0100 Subject: [PATCH] remove newline from JSON output --- 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 3f47def2..cdc269f3 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 << "\n {"; + *output << " {"; 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 << "\n "; + *output << " "; } 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 5bb97027..b543ca05 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 << "\n \"" << getName(); + *output << " \"" << 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 << "\": {" - << "\n \"name\": \"" << getName() << "\"" - << ",\n \"passive\": " << (isPassive() ? "true" : "false") - << ",\n \"write\": " << (isWrite() ? "true" : "false") - << ",\n \"lastup\": " << setw(0) << dec << m_lastUpdateTime; + << " \"name\": \"" << getName() << "\"" + << ", \"passive\": " << (isPassive() ? "true" : "false") + << ", \"write\": " << (isWrite() ? "true" : "false") + << ", \"lastup\": " << setw(0) << dec << m_lastUpdateTime; bool hasData = getLastUpdateTime() != 0; if (hasData || withDefinition) { if (withDefinition && m_srcAddress != SYN) { - *output << ",\n \"qq\": " << dec << static_cast(m_srcAddress); + *output << ", \"qq\": " << dec << static_cast(m_srcAddress); } - *output << ",\n \"zz\": " << dec << static_cast(m_dstAddress); + *output << ", \"zz\": " << dec << static_cast(m_dstAddress); if (withDefinition) { - *output << ",\n \"id\": [" << dec; + *output << ", \"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 << ",\n \"fields\": {"; + *output << ", \"fields\": {"; result_t dret = decodeLastData(false, nullptr, -1, outputFormat, output); if (dret == RESULT_OK) { - *output << "\n }"; + *output << "}"; } else { string prefix = output->str().substr(0, pos); output->str(""); output->clear(); // remove written fields - *output << prefix << ",\n \"decodeerror\": \"" << getResultCode(dret) << "\""; + *output << prefix << ", \"decodeerror\": \"" << getResultCode(dret) << "\""; } } if (withDefinition) { - *output << ",\n \"fielddefs\": ["; + *output << ", \"fielddefs\": ["; m_data->dump(false, true, output); - *output << "\n ]"; + *output << "]"; } } - *output << "\n }"; + *output << "}"; } @@ -2670,7 +2670,7 @@ bool MessageMap::decodeCircuit(const string& circuit, OutputFormat outputFormat, return false; } if (outputFormat & OF_JSON) { - *output << "\n \"name\": \"" << it->second->getName() << "\""; + *output << " \"name\": \"" << it->second->getName() << "\""; } else { *output << it->second->getName() << "="; }