View Source Jcs (jcs v0.2.0)
A pure Elixir implementation of RFC 8785: JSON Canonicalization Scheme (JCS)
Based on Python 3 implementation at https://github.com/titusz/jcs
Requires Erlang OTP 25 (Ryu float_to_binary(number, [:short])
support), and
therefore Elixir 1.14.
Summary
Functions
Encodes data into a JSON string, in a canonical form according to RFC 8785.
Returns a JSON representation of a string, escaping characters per RFC 8785
Returns a JSON representation of a string, escaping characters in the range U+0000 through U+007E per RFC 8785. Values above U+0073 are serialized using lowercase hexadecimal Unicode notation ("\uhhhh" or "\u{hhhhh}")
Given either a String, or single codepoint, returns a string concatenating "\uhhhh" and "\u{hhhhh}" elements.
Given either a binary, a list of codepoints, a single codepoint (unicode character) or its integer value, returns a flattened list of UTF-16 encoded values. This list can be used to sort object names as specified in the RFC.
Functions
Encodes data into a JSON string, in a canonical form according to RFC 8785.
Canonicalizes nested object entries and sorts them by their names.
Entries with the same name are sorted by value.
Numbers are encoded to produce the shortest exact values possible,
using the Erlang function :erlang.float_to_binary/2
, which seems
to have differing results depending on the OTP release. Steps
from ECMA-262 - Abstract Operations - 7.1.12.1 - NumberToString
are applied to the results of the conversion to produce the final
encoding.
The ordering for the name and value sorting is determined by converting each name and value into UTF-16, while the actual resultant JSON string is encoded in UTF-8, according to the particular rules in RFC 8785 - 3.2.2.2 - Serialization of Strings.
Returns a JSON representation of a string, escaping characters per RFC 8785:
If the Unicode value falls within the traditional ASCII control character range (U+0000 through U+001F), it MUST be serialized using lowercase 4-digit hexadecimal Unicode notation ("\uhhhh") unless it is in the set of predefined JSON control characters U+0008, U+0009, U+000A, U+000C, or U+000D, which MUST be serialized as "", " ", " ", "", and " ", respectively.
If the Unicode value is outside of the ASCII control character range, it MUST be serialized "as is" unless it is equivalent to U+005C () or U+0022 ("), which MUST be serialized as "\" and """, respectively.
Returns a JSON representation of a string, escaping characters in the range U+0000 through U+007E per RFC 8785. Values above U+0073 are serialized using lowercase hexadecimal Unicode notation ("\uhhhh" or "\u{hhhhh}")
See encode_basestring/1
for details of the encoding of values
U+005C (), U+0022 (") and U+0000 through U+001F.
Given either a String, or single codepoint, returns a string concatenating "\uhhhh" and "\u{hhhhh}" elements.
Given either a binary, a list of codepoints, a single codepoint (unicode character) or its integer value, returns a flattened list of UTF-16 encoded values. This list can be used to sort object names as specified in the RFC.