},
- // Inserted after any of the #add_match directives
- #precedence 1000 (w: ^io.Writer, v: $T) -> Encoding_Error {
- return .Unsupported_Type;
- }
+ // // Inserted after any of the #add_match directives
+ // #precedence 1000 (w: ^io.Writer, v: $T) -> Encoding_Error {
+ // return .Unsupported_Type;
+ // }
}
\ No newline at end of file
decoded_json.root["test"]->as_str() |> println();
}
- json.encode(^stdio.print_writer, decoded_json.root);
+ json.encode(^stdio.print_writer, decoded_json.root["sub"]);
+ print("\n");
+
+ v_arr := array.make(Vector2);
+ defer array.free(^v_arr);
+
+ array.push(^v_arr, .{ 10, 20 });
+ array.push(^v_arr, .{ 12.34, 45.67 });
+ array.push(^v_arr, .{ 0, -10 });
+
+ if err := json.encode(^stdio.print_writer, v_arr); err != .None {
+ printf("Error formatting json %i", cast(i32) err);
+ }
print("\n");
}
-
\ No newline at end of file
+
+Vector2 :: struct {
+ x, y: f32;
+}
+
+#add_match json.encode, (w: ^io.Writer, v: Vector2) -> json.Encoding_Error {
+ io.write_format(w, "{\"x\":%f,\"y\":%f}", v.x, v.y);
+
+ return .None;
+}
\ No newline at end of file