Zig
Zig
JSON Hex Encoding
See more JSON Examples
Let's say your JSON contains content that is hex encoded like this: \u05d1\u05d3\u05d9\u05e7This example shows how to get the decoded string.
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const s = "{ \"example\": \"\\u05d1\\u05d3\\u05d9\\u05e7\" }";
const json = try chilkat.JsonObject.init();
defer json.deinit();
try json.load(s);
// When getting the member data, it is automatically decoded.
std.debug.print("member data: {s}\n", .{try json.stringOf(alloc, "example")});
// Output:
// member data: בדיק
// When getting the full JSON, it remains encoded. This is expected and intentional.
std.debug.print("full JSON: {s}\n", .{try json.emit(alloc)});
// Output:
// full JSON: {"example":"\u05d1\u05d3\u05d9\u05e7"}
// To get the full JSON without the encoding, you can decode manually.
const sb = try chilkat.StringBuilder.init();
defer sb.deinit();
json.emitSb(sb) catch {};
// The hex encoding used by JSON is utf-8.
sb.decode("json", "utf-8") catch {};
std.debug.print("{s}\n", .{try sb.getAsString(alloc)});
// Output:
// {"example":"בדיק"}
}