c3c icon indicating copy to clipboard operation
c3c copied to clipboard

Add JSON marshaling library

Open sudison opened this issue 5 months ago • 8 comments

Refer to request: https://github.com/c3lang/c3c/issues/1395

  • Add json_marshal.c3 with Go-style API (json::marshal, json::marshal_value, json::marshal_array)
  • Support all primitive types: String, int, float, double, bool
  • Support enums (always marshaled as enum names, regardless of associated values)
  • Support nested structs and arrays of any supported type
  • Use temp allocator for memory-safe operation
  • Comprehensive test suite with 15 test cases covering all features
  • Follow C3 coding style with proper and kindof usage

sudison avatar Jun 30 '25 03:06 sudison

I think that serialization and deserialization are more common and frequently used terms.

data-man avatar Jun 30 '25 09:06 data-man

I think that serialization and deserialization are more common and frequently used terms.

serialization and deserialization are too long for a function name, IMHO. I'd prefer shorter name like, marshal/unmarshal, like in golang.

sudison avatar Jun 30 '25 18:06 sudison

While I do not have any power over merging PRs, I went ahead and looked at the code. The naming issue aside (I also prefer serialize/deserialize), the code seems to be written in a weird way. You claim to follow the C3 coding style, but the use of doc-comments and optionals is just plain different (and in case of doc-comments just wrong) from what the rest of the standard library uses.

If you're serious about getting this working and up to standards, feel free to join the Discord to chat about improving this. (Discord link: https://discord.gg/qN76R87, can also be found on the C3 website.)

Sorry about the that, most of the code and docs are written by AI, both AI and myself are still learning how to writing c3 code properly. Thanks for your feedback, all are addressed. I will join Discord soon.

sudison avatar Jul 02 '25 05:07 sudison

I don't know how I feel knowing this is done using AI. I feel like it's weird to jump into an open-source project and start letting AI make contributions. To me I'd feel like I want to do contributions myself to learn the language and become fluid in it.

On the other hand the implementation seems ok.

But this is the last you'll hear from me about this I think, the rest is for @lerno to decide.

While I use AI to generate code and documentation, I am still a significant contributor to the final code. It takes considerable effort—often an hour or more—to guide the AI to write correct code. Because there is very little C3 code available for training, the AI's knowledge of the language is limited, which requires a lot of manual guidance to get it working correctly. So, why bother using AI at all? I believe AI-assisted programming is the future, whether we like it or not. I wanted to test AI's capabilities on a niche programming language. I've been very satisfied, as it can write decent C3 code.

sudison avatar Jul 03 '25 07:07 sudison

I don't have a set opinion on AI. However, any non-trivial feature should currently be incubated before inclusion. So the process is this:

  1. Create a repo for it.
  2. Send a request for feedback (file an issue)
  3. Handle incoming pull request for improvements and fixes.
  4. The library is then either included or instead recommended to be set up as a separate library. There has to be some curation as to what goes into the stdlib as it adds maintenance costs.

lerno avatar Jul 03 '25 21:07 lerno

Are you alright with closing this @sudison and offering it through the regular process of an incubator?

lerno avatar Jul 11 '25 12:07 lerno

Are you alright with closing this @sudison and offering it through the regular process of an incubator?

Yeah, I just created a repo: https://github.com/sudison/c3-json

sudison avatar Jul 12 '25 08:07 sudison

@sudison have you got good feedback on the repo?

lerno avatar Jul 21 '25 09:07 lerno