1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//! # FracturedJson
//!
//! A JSON formatter that produces human-readable output with smart line breaks,
//! table-like alignment, and optional comment support.
//!
//! FracturedJson formats JSON data in a way that's easy for humans to read while
//! remaining fairly compact:
//!
//! - Arrays and objects are written on single lines when they're short and simple enough
//! - When several lines have similar structure, their fields are aligned like a table
//! - Long arrays are written with multiple items per line
//! - Comments (non-standard JSON) can be preserved if enabled
//!
//! ## Command-Line Tool
//!
//! This crate includes the `fjson` CLI tool for formatting JSON from the terminal:
//!
//! ```sh
//! # Install
//! cargo install fracturedjson
//!
//! # Format JSON from stdin
//! echo '{"a":1,"b":2}' | fjson
//!
//! # Format a file
//! fjson input.json -o output.json
//!
//! # Minify
//! fjson --compact < input.json
//! ```
//!
//! Run `fjson --help` for all options.
//!
//! ## Quick Start
//!
//! ```rust
//! use fracturedjson::Formatter;
//!
//! let input = r#"{"name":"Alice","scores":[95,87,92],"active":true}"#;
//!
//! let mut formatter = Formatter::new();
//! let output = formatter.reformat(input, 0).unwrap();
//!
//! println!("{}", output);
//! ```
//!
//! ## Serializing Rust Types
//!
//! Any type implementing [`serde::Serialize`] can be formatted directly:
//!
//! ```rust
//! use fracturedjson::Formatter;
//! use serde::Serialize;
//!
//! #[derive(Serialize)]
//! struct Player {
//! name: String,
//! scores: Vec<i32>,
//! }
//!
//! let player = Player {
//! name: "Alice".into(),
//! scores: vec![95, 87, 92],
//! };
//!
//! let mut formatter = Formatter::new();
//! let output = formatter.serialize(&player, 0, 100).unwrap();
//! ```
//!
//! ## Configuration
//!
//! Customize formatting behavior through [`FracturedJsonOptions`]:
//!
//! ```rust
//! use fracturedjson::{Formatter, EolStyle, NumberListAlignment};
//!
//! let mut formatter = Formatter::new();
//! formatter.options.max_total_line_length = 80;
//! formatter.options.indent_spaces = 2;
//! formatter.options.json_eol_style = EolStyle::Lf;
//! formatter.options.number_list_alignment = NumberListAlignment::Decimal;
//!
//! let output = formatter.reformat(r#"{"values":[1,2,3]}"#, 0).unwrap();
//! ```
//!
//! ## Comment Support
//!
//! FracturedJson can handle JSON with comments (non-standard) when enabled:
//!
//! ```rust
//! use fracturedjson::{Formatter, CommentPolicy};
//!
//! let input = r#"{
//! // This is a comment
//! "name": "Alice"
//! }"#;
//!
//! let mut formatter = Formatter::new();
//! formatter.options.comment_policy = CommentPolicy::Preserve;
//!
//! let output = formatter.reformat(input, 0).unwrap();
//! ```
//!
//! ## Example Output
//!
//! Given appropriate input, FracturedJson produces output like:
//!
//! ```json
//! {
//! "SimilarObjects": [
//! { "type": "turret", "hp": 400, "loc": {"x": 47, "y": -4} },
//! { "type": "assassin", "hp": 80, "loc": {"x": 12, "y": 6} },
//! { "type": "berserker", "hp": 150, "loc": {"x": 0, "y": 0} }
//! ]
//! }
//! ```
//!
//! Notice how:
//! - Similar objects are aligned in a table format
//! - Numbers are right-aligned within their columns
//! - The structure remains compact while being highly readable
pub use crateFracturedJsonError;
pub use crateFormatter;
pub use crate;
pub use crate;