Skip to content

Escaping of forward slash in JSON output method #530

Description

@michaelhkay

The fact that we escape forward slash in the JSON output method has proved unpopular with quite a few users.

The rationale for doing it is discussed at https://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped

The short summary is that it's only needed when JSON is inserted into an HTML script element, and then only when immediately followed by >.

There's a workaround using character maps but it's really clumsy.

I don't want to escape forward slashes by default in the xdm-to-json() function because they appear so often in namespaces and it adds an awful lot of visual clutter. That means that our JSON formatter needs an option to suppress this escaping, which means we might as well provide user control over it as an output property...

Adding a new output property just for this purpose is rather heavyweight both in the specs and in our implementation, but I can't think of a better solution. So I propose adding escape-solidus, values yes/no, default (for compatibility) yes.

Yes, someone will ask about the name. Surely no-one calls it a solidus? Well, Unicode does, and I think we should use the official name. And it avoids arguing about whether it should be slash or forwards-slash or forward-slash. At least I'm not proposing virgule.

Activity

  1. added
    EnhancementA change or improvement to an existing feature
    SerializationAn issue related to the Serialization spec
    on May 31, 2023
  2. michaelhkay commented on Jun 9, 2023

    @michaelhkay
    ContributorAuthor

    This was addressed by PR #534 which was accepted.

  3. michaelhkay commented on Oct 17, 2023

    @michaelhkay
    ContributorAuthor

    Typo noted (3 times):

    5.1.13 XML Output Method: the escape-solidus Parameter

    The escape-uri-attributes parameter is not applicable to the XML ...

    Also: we should add the escape-solidus option to the xml-to-json function

  4. ChristianGruen commented on Oct 23, 2023

    @ChristianGruen
    Contributor

    @michaelhkay This issue can probably be closed… Unless we decide to rename escape-solidus to json-escape-solidus or escape-json-solidus (analogous to json-node-output-method). Otherwise, people might assume that the parameter affects other serialization methods as well.

  5. michaelhkay commented on Nov 27, 2023

    @michaelhkay
    ContributorAuthor

    The issue remains open, to correct the typo whereby the escape-solidus parameter is wrongly referred to as escape-uri-attributes

  6. michaelhkay commented on Jan 10, 2024

    @michaelhkay
    ContributorAuthor

    PR #942 has been raised to fix the remaining typo.

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

    EnhancementA change or improvement to an existing featureSerializationAn issue related to the Serialization spec

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions