How to encode HashMap to json stirng?

Hi sorry for a reply to an old thread, but this solution did not help me because it did not offer an example on how to implement jsonStringify function on some struct.

I found this example which should work for a situation like this

          pub fn jsonStringify(self: @This(), jws: anytype) !void {
              try jws.beginObject();
              var it = self.map.iterator();
              while (it.next()) |kv| {
                  try jws.objectField(kv.key_ptr.*);
                  try jws.write(kv.value_ptr.*);
              }
              try jws.endObject();
          }

there is some more info here
and here are docs to json.WriteStream

3 Likes