Browse Source

Use `json` field tag for `json.marshal`

gingerBill 2 years ago
parent
commit
28ad4f8623
1 changed files with 5 additions and 1 deletions
  1. 5 1
      core/encoding/json/marshal.odin

+ 5 - 1
core/encoding/json/marshal.odin

@@ -302,7 +302,11 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err:
 		
 		
 		for name, i in info.names {
 		for name, i in info.names {
 			opt_write_iteration(w, opt, i) or_return
 			opt_write_iteration(w, opt, i) or_return
-			opt_write_key(w, opt, name) or_return
+			if json_name := string(reflect.struct_tag_get(info.tags[i], "json")); json_name != "" {
+				opt_write_key(w, opt, json_name) or_return
+			} else {
+				opt_write_key(w, opt, name) or_return
+			}
 
 
 			id := info.types[i].id
 			id := info.types[i].id
 			data := rawptr(uintptr(v.data) + info.offsets[i])
 			data := rawptr(uintptr(v.data) + info.offsets[i])