remove newline from JSON output

This commit is contained in:
john30
2018-12-25 14:11:33 +01:00
parent 90eeb20466
commit d3e496ef6b
2 changed files with 17 additions and 17 deletions
+2 -2
View File
@@ -463,7 +463,7 @@ void SingleDataField::dumpPrefix(bool prependFieldSeparator, bool asJson, ostrea
if (prependFieldSeparator) { if (prependFieldSeparator) {
*output << FIELD_SEPARATOR; *output << FIELD_SEPARATOR;
} }
*output << "\n {"; *output << " {";
appendJson(false, "name", m_name, true, output); appendJson(false, "name", m_name, true, output);
} else { } else {
dumpString(prependFieldSeparator, m_name, output); dumpString(prependFieldSeparator, m_name, output);
@@ -538,7 +538,7 @@ result_t SingleDataField::read(const SymbolString& data, size_t offset,
*output << ","; *output << ",";
} }
if (fieldIndex < 0 && !shortFormat) { if (fieldIndex < 0 && !shortFormat) {
*output << "\n "; *output << " ";
} }
if (outputIndex >= 0 || m_name.empty() || !(outputFormat & OF_NAMES)) { if (outputIndex >= 0 || m_name.empty() || !(outputFormat & OF_NAMES)) {
if (fieldIndex < 0) { if (fieldIndex < 0) {
+15 -15
View File
@@ -937,7 +937,7 @@ void Message::decodeJson(bool leadingSeparator, bool appendDirection, bool addRa
if (leadingSeparator) { if (leadingSeparator) {
*output << ","; *output << ",";
} }
*output << "\n \"" << getName(); *output << " \"" << getName();
if (appendDirection) { if (appendDirection) {
if (isPassive()) { if (isPassive()) {
*output << "-u"; *output << "-u";
@@ -947,18 +947,18 @@ void Message::decodeJson(bool leadingSeparator, bool appendDirection, bool addRa
} }
bool withDefinition = (outputFormat & OF_DEFINTION) != 0; bool withDefinition = (outputFormat & OF_DEFINTION) != 0;
*output << "\": {" *output << "\": {"
<< "\n \"name\": \"" << getName() << "\"" << " \"name\": \"" << getName() << "\""
<< ",\n \"passive\": " << (isPassive() ? "true" : "false") << ", \"passive\": " << (isPassive() ? "true" : "false")
<< ",\n \"write\": " << (isWrite() ? "true" : "false") << ", \"write\": " << (isWrite() ? "true" : "false")
<< ",\n \"lastup\": " << setw(0) << dec << m_lastUpdateTime; << ", \"lastup\": " << setw(0) << dec << m_lastUpdateTime;
bool hasData = getLastUpdateTime() != 0; bool hasData = getLastUpdateTime() != 0;
if (hasData || withDefinition) { if (hasData || withDefinition) {
if (withDefinition && m_srcAddress != SYN) { if (withDefinition && m_srcAddress != SYN) {
*output << ",\n \"qq\": " << dec << static_cast<unsigned>(m_srcAddress); *output << ", \"qq\": " << dec << static_cast<unsigned>(m_srcAddress);
} }
*output << ",\n \"zz\": " << dec << static_cast<unsigned>(m_dstAddress); *output << ", \"zz\": " << dec << static_cast<unsigned>(m_dstAddress);
if (withDefinition) { if (withDefinition) {
*output << ",\n \"id\": [" << dec; *output << ", \"id\": [" << dec;
for (auto it = m_id.begin(); it < m_id.end(); it++) { for (auto it = m_id.begin(); it < m_id.end(); it++) {
if (it > m_id.begin()) { if (it > m_id.begin()) {
*output << ", "; *output << ", ";
@@ -975,24 +975,24 @@ void Message::decodeJson(bool leadingSeparator, bool appendDirection, bool addRa
*output << dec; *output << dec;
} }
size_t pos = (size_t)output->tellp(); size_t pos = (size_t)output->tellp();
*output << ",\n \"fields\": {"; *output << ", \"fields\": {";
result_t dret = decodeLastData(false, nullptr, -1, outputFormat, output); result_t dret = decodeLastData(false, nullptr, -1, outputFormat, output);
if (dret == RESULT_OK) { if (dret == RESULT_OK) {
*output << "\n }"; *output << "}";
} else { } else {
string prefix = output->str().substr(0, pos); string prefix = output->str().substr(0, pos);
output->str(""); output->str("");
output->clear(); // remove written fields output->clear(); // remove written fields
*output << prefix << ",\n \"decodeerror\": \"" << getResultCode(dret) << "\""; *output << prefix << ", \"decodeerror\": \"" << getResultCode(dret) << "\"";
} }
} }
if (withDefinition) { if (withDefinition) {
*output << ",\n \"fielddefs\": ["; *output << ", \"fielddefs\": [";
m_data->dump(false, true, output); 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; return false;
} }
if (outputFormat & OF_JSON) { if (outputFormat & OF_JSON) {
*output << "\n \"name\": \"" << it->second->getName() << "\""; *output << " \"name\": \"" << it->second->getName() << "\"";
} else { } else {
*output << it->second->getName() << "="; *output << it->second->getName() << "=";
} }