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

Properly unmarshal JSON values into golang values when inserting table data #335

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

Conversation

ohaibbq
Copy link
Contributor

@ohaibbq ohaibbq commented Jul 9, 2024

Closes #286
Closes #334
Closes #144

@renevall
Copy link

renevall commented Nov 6, 2024

I have the same issue.

Workaround meanwhile we do

func decodePayload(payload string, v any) error {
	err := decodePayloadBigquery(payload, v)
	if err != nil {
		return decodePayloadFromEmulator(payload, &v)
	}

	return nil
}

func decodePayloadBigquery(payload string, v any) error {
	err := json.Unmarshal([]byte(payload), &v)
	if err != nil {
		return fmt.Errorf("failed to unmarshal payload from bigquery: %w", err)
	}

	return nil
}

func decodePayloadFromEmulator(payload string, v any) error {
	payload, err := strconv.Unquote(payload)
	if err != nil {
		return fmt.Errorf("failed to unquote payload: %w", err)
	}

	err = json.Unmarshal([]byte(payload), v)
	if err != nil {
		return fmt.Errorf("failed to unmarshal payload from emulator: %w", err)
	}

	return nil
}

@ohaibbq
Copy link
Contributor Author

ohaibbq commented Nov 6, 2024

@goccy mind reviewing this one for @renevall? Hope you're well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants