I’m trying to learn zig by creating a little application. The application has to send HTTP POST requests to an LMS (Lyrion Music Server). Just some basic commands like play, pause, get currently played track, etc.
According to the documentation the JSON string should look like:
My initial idea was to create a struct and use ‘std.json.stringify’ to get the string that can be sent to the server. But I’m having trouble creating this struct definition. The first two fields, id and method, are easy but how do I define the ‘params’ part. It looks like an array with two entries, the first containing the player id and the second contains another array that holds the actual commands to be sent.
Any help or pointer to documentation is appreciated.
Thanks. I did not know that tuples could be used. And also thanks for reminding me to look at the sources of the standard library as it appears there is valuable information there.
Thanks for this option. I think the solution of using tuples seems a bit easier in my situation. However I was not aware it is this easy to create your own custom serialization. I still have a lot to learn about Zig, but am enjoying the process so far.
While I think that your use of blocks looks like a fun idea that also could be really useful for complex jsonStringify functions, I think in this case it isn’t really helpful and makes it look more complicated than it is: