| Crates.io | jxpand |
| lib.rs | jxpand |
| version | 0.1.0 |
| created_at | 2023-11-29 03:37:24.476975+00 |
| updated_at | 2023-11-29 03:37:24.476975+00 |
| description | A tool for expanding JSON data with annotations useful for code generation. |
| homepage | |
| repository | https://github.com/rhysparry/jxpand |
| max_upload_size | |
| id | 1052563 |
| size | 34,697 |
jxpandjxpand is a tool for expanding JSON values from the command line.
The expanded JSON includes additional annotations that make it easier to use with templating engines such as mustache.
The API is still in development and breaking changes may occur until the 1.0 release.
JSON arrays are expanded to include additional annotations relevant to the items in the array.
For example, the array:
[ "foo", "bar", "baz" ]
is expanded to:
{
"values": [
{
"value": "foo",
"first": true,
"last": false,
"index": 0
},
{
"value": "bar",
"first": false,
"last": false,
"index": 1
},
{
"value": "baz",
"first": false,
"last": true,
"index": 2
}
],
"count": 3
}
count annotation is added by substituting the array with an object containing the count key and the original array in the values key.first annotation is true for the first item in the array.last annotation is true for the last item in the array.index annotation is added to every item in the array with the index of the item.Instead of wrapping objects in an array, you can merge the annotations into existing objects. Each annotation is added with a prefix.
For example, the array:
[
{
"foo": "bar"
},
{
"foo": "baz"
}
]
is expanded to:
{
"values": [
{
"foo": "bar",
"_first": true,
"_last": false,
"_index": 0
},
{
"foo": "baz",
"_first": false,
"_last": true,
"_index": 1
}
],
"count": 2
}
All annotations are enabled by default, and disabling an annotation will adjust the output accordingly. If the count annotation is enabled, arrays will no longer be wrapped.
Currently, disabling all item-level annotations will still result in each item being wrapped.
The jxpand tool can be used to expand JSON values from the command line. Its usage can be seen by running:
$ jxpand --help
It supports:
Submit an issue if there is something you would like to see.