Contributing JSON support to Sugar

I believe JSON support isn’t currently in Sugar yet, b ut someone starte working on it in the stable-feature-json branch. I’ll have a look at what the status for this is, later this week.

I checked out the branch on Github but couldn’t find any file there. Is there something I can do to contribute?

Also when I checked Http.pas, I found that the language used to code it was different. What language is that? \

Can you direct me to some documentation to write it in Silver with #if Java etc? I’m familiar with JSON Parsing on all the 3 platforms, so I can help you write it up in Silver or something

Sure. Just start coding and submit a pull request. We do have some rough ideas for what we want XML (we’ll rework/improve that) and JSON parsing APIs to look like, so we might adjust your code based on that, once committed. Unfortunately i don’t have those ideas formalized currently. In general, we like to keep Sugar close to the .NET style APIs, and in particulate, .NET’s (and Cocoas) XML APIs are a good template for what the Sugar APIs for both XML and JSON should look like (and ideally they should become as symmetrical as sensible).

It’s Oxygene. But feel free to sue Swift, for new classes you write.

essentially, just add a new file to the Shared Project, say Json.swift. and use #if ECHOES, #if COOPER, #if NOUGAT to check for the platforms, .NET, Java and Cocoa, respectively. See the other files for examples.

I’d say start with fleshing to an empty API first, we can then review this, before you fill it. How does that sound?

1 Like

The problem with Json Parsing on .Net is that there are many options. We have the JavascriptSerializer class on the web, and JsonValue on Windows Phone. Additionally, people like to use Json.Net instead of the default json serializer so that’s the third option. And then there’s the new System.Json namespace that was added in .Net 4.5 which is the fourth option. I think we should stick to the new System.Json API style since this is the latest from Microsoft. After reviewing the 3 API sets from Microsoft, the simplest of them seems to be the JavascriptSerializer API and is also the API that is closest to Cocoa and I think is the best choice for Sugar. What do you think?

Awesome! I’ll start with a simple and primitive API and paste it here for you to review and then I can formally implement, unit test and submit it as a pull request

1 Like

We do have a partial JSON implementation here: https://github.com/remobjects/sugar/tree/master/Sugar.Data/JSON

(i’m going to test that, and move it to main sugar if it works next week)

1 Like

Awesome, do let me know as I need to use JsonParsing in my project.

On another note, I checked out the JSON library that exists in the repo now and I see that its based on the System.Json API. Don’t you think that its a bit of an overkill creating the entire JsonValue API? It also deviates a lot from Json Parsing on Cocoa. The JavascriptSerializer is much more closer to Cocoa and .Net developers are also familiar with it. Also bear in mind that the System.Json API is still in preview and bound to change. Perhaps we should refocus our efforts on porting the JavascriptSerializer instead of the resource heavy and beta System.Json? What do you think?