Movatterモバイル変換


[0]ホーム

URL:


Search

Lib.rs

Encoding
#json-parser#json-serialization#serde-serialize#hjson#json-format#parser-serialization

serde-hjson

Hjson serialization file format

9 releases(2 stable)

1.1.0Sep 25, 2024
1.0.0Jul 29, 2024
0.9.1Aug 19, 2019
0.9.0Dec 19, 2018
0.0.1Jun 24, 2016

#52 inEncoding

Download history15874/week @ 2024-12-0116150/week @ 2024-12-0815514/week @ 2024-12-156492/week @ 2024-12-225486/week @ 2024-12-2911352/week @ 2025-01-0513531/week @ 2025-01-1211593/week @ 2025-01-1912898/week @ 2025-01-2621680/week @ 2025-02-0218714/week @ 2025-02-0915610/week @ 2025-02-1615620/week @ 2025-02-2314511/week @ 2025-03-0214010/week @ 2025-03-0917862/week @ 2025-03-16

63,472 downloads per month
Used in17 crates(13 directly)

MITlicense

115KB
3KSLoC

hjson-rust for serde

Build Statuscrate

Hjson Intro

{# specify ratein requests/second(because comments are helpful!)  rate:1000// prefer c-style comments?/* feeling old fashioned?*/# did you notice that rate doesn't need quotes?  hey: look ma, no quotesfor strings either!# best of all  notice:[]  anything:?# yes, commas are optional!}

The Rust implementation of Hjson is based on theSerde JSON Serialization Library. For other platforms seehjson.github.io.

This crate is a Rust library for parsing and generating Human JSONHjson. It is built uponSerde, a high performance generic serialization framework.

Install

This crate works with Cargo and can be found oncrates.io with aCargo.toml like:

[dependencies]serde="*"serde-hjson="*"

From the Commandline

Install withcargo install hjson

Hjson, the HumanJSON.Usage:  hjson[options]  hjson[options]<input>  hjson(-h|--help)  hjson(-V|--version)Options:-h--help     Show this screen.-j            Outputas formattedJSON.-c            OutputasJSON.-V--version  Show version.

Sample:

  • runhjson test.json> test.hjson to convert to Hjson
  • runhjson-j test.hjson> test.json to convert to JSON

Usage

externcrate serde;externcrate serde_hjson;useserde_hjson::{Map,Value};fnmain(){// Now let's look at decoding Hjson datalet sample_text=r#"    {        // specify rate in requests/second        rate: 1000        array:        [            foo            bar        ]    }"#;// Decode and unwrap.letmut sample:Map<String, Value>=serde_hjson::from_str(&sample_text).unwrap();// scope to control lifetime of borrow{// Extract the ratelet rate= sample.get("rate").unwrap().as_f64().unwrap();println!("rate:{}", rate);// Extract the arraylet array:&mutVec<Value>= 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 Hjsonlet sample2=serde_hjson::to_string(&sample).unwrap();println!("Hjson:\n{}", sample2);}

API

see Rust doc

History

see history.md

Dependencies

~2.3–3.5MB
~64KSLoC


[8]ページ先頭

©2009-2025 Movatter.jp