Add parameters sort_keys=True and indent=4 to SerializeJSON to pretty print JSON output

47 views
Skip to first unread message

thorste...@googlemail.com

unread,
Apr 21, 2016, 7:41:43 AM4/21/16
to Lucee
Hi,

do you think it would be useful to add parameters sort_keys=True and indent=4 to SerializeJSON to pretty print JSON output?

Like in Python JSON encoder/decoder
https://docs.python.org/3/library/json.html

Regards
Thorsten

Mark Drew

unread,
Apr 21, 2016, 7:52:55 AM4/21/16
to lucee
Sounds like a good idea, but it would be better (IMHO) to follow the stringify method from javascript:


--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/33ac4cc2-536d-4ffb-bf18-bc9d7691083a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

thorste...@googlemail.com

unread,
Apr 21, 2016, 8:04:36 AM4/21/16
to Lucee

Maybe take the best out of both worlds (Python and JavaScript.stringify()).

Andrew Penhorwood

unread,
Apr 21, 2016, 10:26:41 AM4/21/16
to Lucee
The serialize method should not be confused with display methods for output.  The serialize function should only serialize the data.  If you want to pretty print the output that should be another method.

Andrew Penhorwood

Dominic Watson

unread,
Apr 21, 2016, 10:45:06 AM4/21/16
to lu...@googlegroups.com
@Andrew I think that's a tough call. From an efficiency and accuracy point of view - I think it would make most sense to pretty print at the point of serialization to avoid needing to re-parse. I'm not sure that adding options around the format of serialization is necessarily at odds with the purpose of a serialization method either - though I'm not 100% sold.

--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Pixl8 Interactive, 3 Tun Yard, Peardon Street, London
SW8 3HT, United Kingdom

T: +44 [0] 845 260 0726 W: www.pixl8.co.uk E: in...@pixl8.co.uk

Follow us on: Facebook Twitter LinkedIn
CONFIDENTIAL AND PRIVILEGED - This e-mail and any attachment is intended solely for the addressee, is strictly confidential and may also be subject to legal, professional or other privilege or may be protected by work product immunity or other legal rules. If you are not the addressee please do not read, print, re-transmit, store or act in reliance on it or any attachments. Instead, please email it back to the sender and then immediately permanently delete it. Pixl8 Interactive Ltd Registered in England. Registered number: 04336501. Registered office: 8 Spur Road, Cosham, Portsmouth, Hampshire, PO6 3EB

thorste...@googlemail.com

unread,
Apr 21, 2016, 1:42:46 PM4/21/16
to Lucee
I guess it's an edge case.

Igal @ Lucee.org

unread,
Apr 21, 2016, 2:04:29 PM4/21/16
to lu...@googlegroups.com
I agree with Andrew on this one.

In most cases when you serialize an object it is for storage or transfer, and you don't care about formatting.  You usually care about formatting when you output it to the browser for the user to view/edit.

We already have the toString() built-in function, maybe we can overload it with options for that purpose.  Another option is to add a JsonFormat() function, along the lines of the other *Format() functions.

Igal Sapir
Lucee Core Developer
Lucee.org

Reply all
Reply to author
Forward
0 new messages