json-flattening
A Rust library for flattening and unflattening JSON structures. Uses serde_json
for JSON serialization and deserialization.
Features
- Flatten JSON: Convert nested JSON structures into a flattened form.
- Unflatten JSON: Convert flattened JSON structures back to nested form.
Installation
Add this library to your Cargo.toml
:
[]
= "0.1.0"
Usage
use ;
Example
Original JSON
Flattened JSON
Explanation:
-
"x[0][0]": "y"
and"x[0][1]": "z"
: The first element of arrayx
is itself an array, so we represent its elements with indices. -
"x[1].p": "q"
: The second element of arrayx
is an object with a key-value pair, so we represent it with dot notation. -
"x[2][0]": "r"
and"x[2][1]": "s"
: The third element of arrayx
is again an array, so we use indices. -
"x[3][0].u": "v"
and"x[3][1].w": "x"
: The fourth element of arrayx
is an array of objects. We use indices for the outer array and dot notation for the objects. -
"x[4][0]": "y"
and"x[4][1]": "z"
: The fifth element of arrayx
is similar to the first, so we again use indices.