Skip to content

haze/zig-json-decode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zig-json-decode

To use, simply clone and link in your zig project

Example

// ./build.zig =====
exe.addPackagePath("zig-json-decode", "zig-json-decode/src/main.zig");

// ./src/main.zig =====
const Decodable = @import("zig-json-decode").Decodable;
const Skeleton = struct {
  key: []const u8,
  
  // json key mapping 
  const json_key: []const u8 = "oddly_named_key";
};

const FleshedType = Decodable(Skeleton);
//...
const json = 
  \\{"oddly_named_key": "test"}
;
const foo = try FleshedType.fromJson(.{}, allocator, (try parser.parse(json)).root.Object);

Features

  • Map json keys to struct fields
  • Dump objects as JSON
  • Create custom decode functions specifically tailored to skeleton structs

TODO

  • Alternative key names

About

Create a zig type to easily decode json from a struct

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages