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

Add json.unparse: RTTI-less conversion from json.Value to []u8 #4628

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bullyingteen
Copy link

@bullyingteen bullyingteen commented Dec 25, 2024

This is a follow up PR to the smalltalk we had in Discord/General/Beginners.

Introduction

While trying out odin's encoding/json module I've found out that the only way to convert json.Value to []u8/string was to use json.marshal (docs lack that information).
Which feels very unnatural and misleading to me as a C/C++ developer. So I did implement json.unparse. It probably has a tiny bit of performance boost due to it being RTTI-less.

Added test case for json.unparse, tested it on my windows 11.

Named it json.unparse for consistency with json.parse, but naming suggestions are wellcome.

Bonus

Fixed an Unsupported_Type error in json.marshal on (rawptr)nil values.

P.S.

json.marshal uses Raw_Map routines when converting json.Object, but it requires runtime.Type_Info for accessing Map_Info hence I used simple k/v for-loop over map. Let me know if traversing Raw_Map buckets is preferred for some reason. I might implement it that way instead.

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