circuits-parser
Safe HaskellNone
LanguageGHC2024

Circuit.Parser.Json.Unescape

Description

Unescaping of JSON string literals.

The input is the raw slice between the quotes, escapes intact. Output is decoded Text. The pure-Haskell equivalent of aeson's unescapeText, minus the C fast path: no escapes means one decodeUtf8' and done.

Synopsis

Documentation

unescape :: ByteString -> Either String Text Source #

Unescape a raw JSON string slice (the bytes between the quotes) to Text.

>>> unescape (C.pack "hello")
Right "hello"
>>> unescape (C.pack "a\\nb")
Right "a\nb"
>>> unescape (C.pack "\\u0041\\u00e9")
Right "A\233"
>>> unescape (C.pack "\\uD834\\uDD1E")
Right "\119070"
>>> unescape (C.pack "bad\\x")
Left "invalid escape: \\x"