Opened 10 years ago

Closed 9 years ago

#7180 closed Bugs (fixed)

Property Tree: json_write() pretty = false option not fully respected for arrays

Reported by: Paul Chandler <mailslot@…> Owned by: Sebastian Redl
Milestone: To Be Determined Component: property_tree
Version: Boost Development Trunk Severity: Problem
Keywords: property_tree json_write pretty indent Cc: n.sakisaka@…

Description

When outputting an array with "pretty" set to false, indentation is output blindly before the closing brace. This has the potential to waste a lot of space in certain usage scenarios... like my own :)

Example:

["1","2"            ]

Expected:

["1","2"]

Patch:

diff -dur boost.old/property_tree/detail/json_parser_write.hpp boost.new/property_tree/detail/json_parser_write.hpp
--- boost.old/property_tree/detail/json_parser_write.hpp	2012-07-26 19:42:10.000000000 -0700
+++ boost.new/property_tree/detail/json_parser_write.hpp	2012-07-26 19:43:34.000000000 -0700
@@ -93,7 +93,8 @@
                     stream << Ch(',');
                 if (pretty) stream << Ch('\n');
             }
-            stream << Str(4 * indent, Ch(' ')) << Ch(']');
+            if (pretty) stream << Str(4 * indent, Ch(' '));
+            stream << Ch(']');
 
         }
         else

Attachments (1)

jsonPrettyPrint.patch (604 bytes ) - added by Paul Chandler <mailslot@…> 10 years ago.
Proposed patch

Download all attachments as: .zip

Change History (5)

by Paul Chandler <mailslot@…>, 10 years ago

Attachment: jsonPrettyPrint.patch added

Proposed patch

comment:1 by Nana Sakisaka <n.sakisaka@…>, 10 years ago

This is a duplicate of #7072. See my comment on #7072 for my proposal.

comment:2 by Nana Sakisaka <n.sakisaka@…>, 10 years ago

Cc: n.sakisaka@… added

comment:3 by Sebastian Redl, 9 years ago

Status: newassigned

Fixed in develop in 530e6fe.

comment:4 by Sebastian Redl, 9 years ago

Resolution: fixed
Status: assignedclosed

Merged to master in 85f8d8866ccf.

Note: See TracTickets for help on using tickets.