An open API service indexing awesome lists of open source software.

https://github.com/javiorfo/prettizy

Zig library to prettify JSON and XML files
https://github.com/javiorfo/prettizy

json prettifier xml zig zig-library

Last synced: 11 months ago
JSON representation

Zig library to prettify JSON and XML files

Awesome Lists containing this project

README

          

# prettizy
*Zig library to prettify JSON and XML strings*

## Caveats
- Required Zig version: **0.13**
- This library has been developed on and for Linux following open source philosophy.

## Usage
```zig
const std = @import("std");
const prettizy = @import("prettizy");

pub fn main() !void {
// Arena Allocator is recommended to avoid internal leaks
var gpa = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer gpa.deinit();
const allocator = gpa.allocator();

const json_string = "{\"name\":\"John\",\"age\":30,\"city\":\"New York\",\"hobbies\":[\"reading\",\"traveling\"], \"obj\":{\"field\":[1,2]}}";
const formatted_json = try prettizy.json.prettify(allocator, json_string, .{});
std.debug.print("{s}\n", .{formatted_json});

const xml_input = "City Library

Main St123MetropolisNY12345
40.7128-74.0060The Great GatsbyF. ScottFitzgerald1925Fiction9780743273565available5";
const formatted_xml = try prettizy.xml.prettify(allocator, xml_input, .{ .tab_space = 4 });
std.debug.print("{s}\n", .{formatted_xml});
}
```

## Installation
#### In `build.zig.zon`:
```zig
.dependencies = .{
.prettizy = .{
.url = "https://github.com/javiorfo/prettizy/archive/refs/heads/master.tar.gz",
// .hash = "hash suggested",
// the hash will be suggested by zig build
},
}
```

#### In `build.zig`:
```zig
const dep = b.dependency("prettizy", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("prettizy", dep.module("prettizy"));
```

---

### Donate
- **Bitcoin** [(QR)](https://raw.githubusercontent.com/javiorfo/img/master/crypto/bitcoin.png) `1GqdJ63RDPE4eJKujHi166FAyigvHu5R7v`
- [Paypal](https://www.paypal.com/donate/?hosted_button_id=FA7SGLSCT2H8G)