Giter Site home page Giter Site logo

json_keyquotes_convert_rs's Introduction

Crate status

crates.io docs.rs License

Pipeline status

Test pipeline Crates.io deployment pipeline

Installation

cargo add json_keyquotes_convert

Example usage

  • For more information, look at the docs.
Using the builder pattern (recommended):
use json_keyquotes_convert::{JsonKeyQuoteConverter, Quotes};

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

// JSON string will now be: {\"key\": \"va\\nl\"}
// Raw JSON will now be: {"key": "va\nl"}
Using functions:
use json_keyquotes_convert::{json_key_quote_utils, Quotes};

let json_added = json_key_quote_utils::json_add_key_quotes("{key: \"va\nl\"}", Quotes::default());
let json_escaped = json_key_quote_utils::json_escape_ctrlchars(&json_added);

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

Important information

Crate support legend

Great Good Unsupported
✔️
Automatically Configurable Unsupported

Crate support

** Any unlisted features might be unsupported. **

  • Adding quotes around JSON keys:
    • Double-quotes: ✔️ (default)
    • Single-quotes: ✅
  • Removing quotes around JSON keys:
    • Double-quotes: ✔️
    • Single-quotes: ✔️
  • Supported quotes around JSON string values:
    • Double-quotes: ✔️
    • Single-quotes: ✔️
  • Supports control character escaping in JSON string values:
    • Newline (\n): ✔️ ✅
    • Tab (\t): ✔️ ✅
    • Carriage return (\r): ✔️ ✅
  • Supports control character unescaping in JSON string values:
    • Newline (\n): ✔️ ✅
    • Tab (\t): ✔️ ✅
    • Carriage return (\r): ✔️ ✅
  • Supported ✔️ 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 ✔️ 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:

Changelog

Contributing

  • All contributions are welcome. I will do my best to reply to all questions and PR's.
  • Please do note that all contributions made to this crate will be made available using the current license (MIT license).

Third party licenses

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.