Crate status

crates.io docs.rs License

Pipeline status

Test pipeline Crates.io deployment pipeline

Installation

cargo add json_keyquotes_convert

Example usage

Using the builder pattern (recommended):

```rust use jsonkeyquotesconvert::{JsonKeyQuoteConverter, Quotes};

let json = JsonKeyQuoteConverter::new("{key: \"va\nl\"}", Quotes::default()) .addkeyquotes().escape_ctrlchars().json();

// JSON string will now be: {\"key\": \"va\nl\"} // Raw JSON will now be: {"key": "va\nl"} ```

Using functions:

```rust use jsonkeyquotesconvert::{jsonkeyquote_utils, Quotes};

let jsonadded = jsonkeyquoteutils::jsonaddkeyquotes("{key: \"va\nl\"}", Quotes::default()); let jsonescaped = jsonkeyquoteutils::jsonescapectrlchars(&jsonadded);

// JSON string will now be: {\"key\": \"va\nl\"} // Raw JSON will now be: {"key": "va\nl"} ```

Important information

Crate support legend

| Great | Good | Unsupported | | :----------------: | :-----------------: | :-----------: | | :heavycheckmark: | :whitecheckmark: | :x: | | Automatically | Configurable | Unsupported |

Crate support

* Any unlisted features might be unsupported. * - Adding quotes around JSON keys: - Double-quotes: :heavycheckmark: (default) - Single-quotes: :whitecheckmark: - Removing quotes around JSON keys: - Double-quotes: :heavycheckmark: - Single-quotes: :heavycheckmark: - Supported quotes around JSON string values: - Double-quotes: :heavycheckmark: - Single-quotes: :heavycheckmark: - Supports control character escaping in JSON string values: - Newline (\n): :heavycheckmark: :whitecheckmark: - Tab (\t): :heavycheckmark: :whitecheckmark: - Supports control character unescaping in JSON string values: - Newline (\n): :heavycheckmark: :whitecheckmark: - Tab (\t): :heavycheckmark: :whitecheckmark: - Supported :heavycheckmark: characters in JSON keys: - [A-Z] [a-z] [0-9] ` ~ ! @ # $ % € ^ & * ( ) - _ = + \ | ; " ' . < > / ? \r \n \t \f \v <U+0020>(Space) - Note: ' and " and their escaped variants could be misinterpreted as keyquotes when used as the last character in a JSON key. It is therefore not recommended to start or end a JSON key with these characters. - Supported :heavycheckmark: characters in JSON values: - [A-Z] [a-z] [0-9] ` ~ ! @ # $ % € ^ & * ( ) - _ = + \ | : ; " ' . < > / ? \r \n \t \f \v <U+0020>(Space)

Please note that this crate does not check whether the output is valid JSON. The functionality of this crate is based on Regular Expressions and uses the regex crate.

Data format

Similar data-formats

The JSON data-format as shown in the tests shares some similarities with both JSON5 and HJSON. Unfortunately, these data-formats differ enough that it can not be parsed by the JSON5 and HJSON parsers, which is why this crate was made.

Usage

The JSON data-format as shown in the tests is used by the following software: - VideoPsalm

Changelog

Contributing

Third party licenses