Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core:encoding/json] When Unmarshalling, Only Match On Struct Tags If Present #4944

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dozn
Copy link
Contributor

@dozn dozn commented Mar 17, 2025

Context

If a struct field contains a struct tag, we should only match on the tag.
https://godbolt.org/z/TcP3974vK

package main

import "core:encoding/json"
import "core:fmt"

main :: proc() {
    JSON := `{"same": 1}`
    s: struct {same: int `json:"different"`}
    json.unmarshal(transmute([]u8)JSON, &s)
    fmt.println(s)
}

Expected

S{same = 0}

Actual

S{same = 1}

What Else I've Done

  • added a comment for json_name_from_tag_value, because I omitted it from a previous commit due to not understanding why it's useful (and fixed a small bug that caused, where struct tags which also contained an omitempty would not work correctly)
  • moved the inline function field_test beside the only place it's used

@dozn dozn changed the title [core:encoding/json] When Unmarshalling, Only Match Struct Tags If Present [core:encoding/json] When Unmarshalling, Only Match On Struct Tags If Present Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant