Structure/Fields order on JSON Output file

293 views
Skip to first unread message

LogSupp

unread,
Dec 6, 2020, 3:41:33 AM12/6/20
to Bots Open Source EDI Translator
Hello,

When I use XML as output file format, it keeps the same fields order than the grammar definition and the translation secuence but when I use JSON output, the field seems to be in random order.

Is there any way to keep the same grammar and translation structure/fields order for a JSON Output File ?  

Thank you,

  

Henk-Jan Ebbers

unread,
Dec 6, 2020, 12:28:12 PM12/6/20
to bots...@googlegroups.com
no, there is not.
(bots is using a dict here, where the sequence of fields is not under control.)

kind regards,
Henk-Jan Ebbers
www.ebbersconsult.com
t: +31 6 14612879

Bots Open Source EDI Translator: http://bots.sourceforge.net
Connect edi-partners at lower costs by smarter testing: www.edi-testrobot.com


--
You received this message because you are subscribed to the Google Groups "Bots Open Source EDI Translator" group.
To unsubscribe from this group and stop receiving emails from it, send an email to botsmail+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/botsmail/e4cfc3af-6399-4ba5-8196-d84d05b5c08bn%40googlegroups.com.

BikeMike

unread,
Dec 6, 2020, 7:50:21 PM12/6/20
to Bots Open Source EDI Translator
Hi,

JSON is in fact unordered by design. You should not attempt to force a specific ordering, and any recipient of JSON data who expects specific ordering has a badly designed process. (eg. they have implemented their own brain-dead parser rather than using a standard library, of which there are many for all common programming languages)

Refer to RFC8259 (or 7159 or 4267) that states in the introduction: An object is an unordered collection of zero or more name/value pairs, where a name is a string and a value is a string, number, boolean, null, object, or array.

Kind Regards,
Mike

BikeMike

unread,
Dec 6, 2020, 8:41:37 PM12/6/20
to Bots Open Source EDI Translator
Maybe you could write a postprocessing script using OrderedDict and read/re-write the JSON output in the order the receiver wants it (but ask them first if they can fix their parser!)

LogSupp

unread,
Dec 14, 2020, 2:05:39 PM12/14/20
to Bots Open Source EDI Translator
Hi Mike /Henk-Jan,

Thanks for your replies, I will explore the postprocessing script using OrderedDict.

Regards,

LogSupp

Eppye Bots

unread,
Dec 14, 2020, 2:09:32 PM12/14/20
to 'Chuck Turco' via Bots Open Source EDI Translator
I do have version that uses sequence as in grammar.....
if you're interested.
kind regards, Henk-Jan Ebbers


LogSupp

unread,
Dec 14, 2020, 2:29:19 PM12/14/20
to Bots Open Source EDI Translator
Hi Henk-Jan,

Yes, i'm interested on it, please let me know how we could do.

Regards,

Eppye Bots

unread,
Dec 14, 2020, 4:12:41 PM12/14/20
to 'Chuck Turco' via Bots Open Source EDI Translator
see attachment (rename to .py)
kind regards, Henk-Jan Ebbers


outmessage.txt

LogSupp

unread,
Dec 14, 2020, 5:50:58 PM12/14/20
to Bots Open Source EDI Translator
Hi  Henk-Jan,

it worked like a charm!

Thank you so much!

Regards,

LogSupp,

BikeMike

unread,
Dec 15, 2020, 3:32:44 AM12/15/20
to Bots Open Source EDI Translator
Probably makes sense for this to be standard Bots behavior, even though json is supposed to be unordered.

Lee Pedley

unread,
Oct 26, 2022, 11:17:55 AM10/26/22
to Bots Open Source EDI Translator
How do we use this structured grammar?
Reply all
Reply to author
Forward
0 new messages