From 26c36e932e62728b7930643c2f1b3ef0e906ae36 Mon Sep 17 00:00:00 2001 From: ygguser <86843390+ygguser@users.noreply.github.com> Date: Sat, 4 Mar 2023 04:07:25 +0300 Subject: [PATCH] README for nu-json. Related to nushell/nushell#8253 (#8289) I propose to add such a README file for the nu-json crate. The crate is good, it is used also by others. However, on crates.io [its page](https://crates.io/crates/nu-json) looks uninformative. Related to https://github.com/nushell/nushell/issues/8253 --------- Co-authored-by: ygguser --- crates/nu-json/CHANGELOG.md | 187 ++++++++++++++++++++++++++++++++++++ crates/nu-json/README.md | 79 +++++++++++++++ 2 files changed, 266 insertions(+) create mode 100644 crates/nu-json/CHANGELOG.md create mode 100644 crates/nu-json/README.md diff --git a/crates/nu-json/CHANGELOG.md b/crates/nu-json/CHANGELOG.md new file mode 100644 index 0000000000..b9d664bdfc --- /dev/null +++ b/crates/nu-json/CHANGELOG.md @@ -0,0 +1,187 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + + + +# [0.76.0] - 2023-02-21 + +### Changed + +- Disable auto-benchmark harness for this crate + +# [0.75.0] - 2023-01-31 + +### Changed + +- Removing unnecessary comments from the code +- Use variable names directly in the format strings +- Apply more recent/nightly clippy lints + +# [0.73.0] - 2022-12-20 + +### Changed + +- Remove unused dev-dependencies +- The lazy_static crate has been replaced by once_cell + +# [0.71.0] - 2022-11-29 + +### Fixed + +- Fixed json parsing + +# [0.71.0] - 2022-11-08 + +### Changed + +- Run a round of clippy --fix to fix a ton of lints + +# [0.67.0] - 2022-08-16 + +### Added + +- Add repository info to all workspace crates + +### Changed + +- Replace the regex crate with the fancy-regex crate + +# [0.66.0] - 2022-07-26 + +### Fixed + +- Prevents panic when parsing JSON containing large number + +# [0.64.0] - 2022-06-15 + +### Changed + +- Address lints from clippy for beta/nightly + +# [0.60.1] - 2022-03-27 + +### Changed + +- Align all of the serde_json crates to the same version (`serde_json = "0.1.39"` --> `serde_json = "0.1"`) + +# [0.60.0] - 2022-03-22 + +### Added + +- Adds tab indentation option for JSON files. + +### Changed + +- Changing the name of the parent project: 'The Nu Project' --> 'The Nushell Project' + +# [0.59.1] - 2022-03-02 + +### Added + +- Add indent flag to to json (first draft) + +### Fixed + +- Fix to json escape logic +- Clippy fixes + +### Changed + +- Update this cargo crate to edition 2021 +- Strip trailing whitespace in files + +# [0.42.0] - 2021-12-28 + +### Fixed + +- fix issue #559: to json -r serializes datetime without spaces + +### Changed + +- add in a raw flag in the command to json + +# [0.41.0] - 2021-12-07 + +### Changed + +- avoid unnecessary allocation (serialization) + +# [0.37.0] - 2021-09-14 + +### Changed + +- Add general refactorings + +# [0.31.0] - 2021-05-11 + +### Fixed + +- Clippy fixes for new Rust version + +# [0.29.2] - 2021-04-06 + +### Fixed + +- Fix typos and capitalization of "Unicode" + +# [0.29.0] - 2021-03-30 + +### Fixed + +- Fix warnings for Rust 1.51 + +# [0.28.0] - 2021-03-09 + +### Changed + +- Preserve order when serializing/deserialize json by default. + +# [0.27.0] - 2021-02-16 + +### Fixed + +- Fix latest clippy warnings + +# [0.25.2] - 2021-01-11 + +### Changed + +- Update num-traits requirement from 0.1.32 to 0.2.14 + +# [0.25.0] - 2021-01-05 + +### Fixed + +- Rust 1.49 Clippy Fixes + +# [0.22.0] - 2020-11-22 + +### Changed + +- Fork of serde-hjson +- The crate added to the 'Nu Project' +- Added Cargo.toml +- LICENSE file added +- Bump version to 0.22 according to the parent project \ No newline at end of file diff --git a/crates/nu-json/README.md b/crates/nu-json/README.md new file mode 100644 index 0000000000..d2eedf6d2b --- /dev/null +++ b/crates/nu-json/README.md @@ -0,0 +1,79 @@ +# nu-json + +[![crate](https://img.shields.io/crates/v/nu-json.svg?style=flat-square)](https://crates.io/crates/nu-json) + +> a fork of [serde_hjson](https://crates.io/crates/serde-hjson). + +> The changes made to this crate are kept in [CHANGELOG](/crates/nu-json/CHANGELOG.md). + + +The Rust implementation of Hjson is based on the [Serde JSON Serialization Library](https://github.com/serde-rs/json). + +This crate is a Rust library for parsing and generating Human JSON [Hjson](https://hjson.github.io). It is built upon [Serde](https://github.com/serde-rs/serde), a high performance generic serialization framework. + +# Install + +This crate works with Cargo and can be found on [crates.io](https://crates.io/crates/nu-json) with a `Cargo.toml` like: + +```toml +[dependencies] +serde = "1" +nu-json = "0.76" +``` + +## From the Commandline + +Add with: +``` + cargo add serde + cargo add nu-json +``` + +# Usage + +```rust +extern crate serde; +extern crate nu_json; + +use nu_json::{Map,Value}; + +fn main() { + + // Now let's look at decoding Hjson data + + let sample_text=r#" + { + # specify rate in requests/second + rate: 1000 + array: + [ + foo + bar + ] + }"#; + + // Decode and unwrap. + let mut sample: Map = nu_json::from_str(&sample_text).unwrap(); + + // scope to control lifetime of borrow + { + // Extract the rate + let rate = sample.get("rate").unwrap().as_f64().unwrap(); + println!("rate: {}", rate); + + // Extract the array + let array : &mut Vec = sample.get_mut("array").unwrap().as_array_mut().unwrap(); + println!("first: {}", array.get(0).unwrap()); + + // Add a value + array.push(Value::String("tak".to_string())); + } + + // Encode to Hjson + let sample2 = nu_json::to_string(&sample).unwrap(); + println!("Hjson:\n{}", sample2); +} +``` +# DOCS + +At the moment, the documentation on [serde_hjson](https://docs.rs/serde-hjson/0.9.1/serde_hjson/) / [serde_json](https://docs.rs/serde_json/1.0.93/serde_json/) is also relevant for nu-json. \ No newline at end of file