Skip to content

xml: Add preserverOrder option #95

Open

Description

@eze1214

Imagine that I have the following XML, and the order of elements is crucial. As far as I understand, a way to handle this case does not exist.
´´´

hello world monde 42 世界 🌏 true content ´´´

It would be convenient to have an option to handle this use case. The JSON result will be more complex, but I will handle this use case appropriately.

Activity

  1. changed the title [-]Add preserverOrder option[/-] [+]xml: Add preserverOrder option[/+] on May 30, 2025
  2. lowlighter commented on May 30, 2025

    @lowlighter
    Owner

    It is technically already (partially) possible, though there's an open issue for that:

    In JS, dictionnaries are ordered so when the parser will build the document, it'll add them in the order it found them.
    For the same reason, when the stringifier iterates on the object properties, it'll add them in the order you registered

    You can verify this behaviour in your browser:

    Reordering objects is achievable but kind of tedious

    const {foo, bar} = JSON.parse(`{"foo":1, "bar":2}`) 
    JSON.stringify({bar, foo}) 

    However, the mentionned issue is because when using an array element, the stringifier will iterate over it at once, effectively loosing order for this particular datatype if your elements were spread across the same node, but for the documents without array you can exploit the behaviour described above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions