Hi all, I am new to zig so I am not sure if I am doing something wrong or if there is a bug in the std.json library.
Practically the deserialization fails until I comment a field which apparently is harmless.
I got the json data from this site: https://dummyjson.com/products
I have reproduced the issue in a github repo but I don't know if it is allowed to post here the link to it.
Here below are the main parts of the code (the issue is with the field brand: []const u8. If I comment it all goes well but it skips that field.
Any ideas?
`const json_data = @embedFile("data.json");
const Products = struct {
products: []struct {
id: usize,
title: []const u8,
description: []const u8,
category: []const u8,
price: f16,
discountPercentage: f16,
rating: f16,
stock: usize,
tags: [][]const u8,
brand: []const u8,
sku: []const u8,
.....
},
total: usize,
skip: usize,
limit: usize,
};
.......
// Deserialize JSON
const options = std.json.ParseOptions{
.ignore_unknown_fields = true,
};
const parsed = try json.parseFromSlice(Products, allocator, json_data, options);
defer parsed.deinit();
const products = parsed.value;
`