diff --git a/include/boost/property_tree/json_parser/detail/write.hpp b/include/boost/property_tree/json_parser/detail/write.hpp index b8ef7eb66..db89b29e6 100644 --- a/include/boost/property_tree/json_parser/detail/write.hpp +++ b/include/boost/property_tree/json_parser/detail/write.hpp @@ -158,7 +158,10 @@ namespace boost { namespace property_tree { namespace json_parser if (!verify_json(pt, 0)) BOOST_PROPERTY_TREE_THROW(json_parser_error("ptree contains data that cannot be represented in JSON format", filename, 0)); write_json_helper(stream, pt, 0, pretty); - stream << std::endl; // outputting endl performs flush + + if (pretty) stream << std::endl; + else stream << std::flush; + if (!stream.good()) BOOST_PROPERTY_TREE_THROW(json_parser_error("write error", filename, 0)); } diff --git a/test/test_json_parser.cpp b/test/test_json_parser.cpp index 6a6ddd24a..e856a3d3e 100644 --- a/test/test_json_parser.cpp +++ b/test/test_json_parser.cpp @@ -257,7 +257,7 @@ const char *bug_data_pr7180_1 = " ]\n" "}\n"; const char *bug_data_pr7180_2 = - "{\"a\":[\"1\",\"2\"]}\n"; + "{\"a\":[\"1\",\"2\"]}"; struct ReadFunc {