# Contributing JSON support to Sugar

**URL:** https://talk.remobjects.com/t/contributing-json-support-to-sugar/6219
**Category:** Elements
**Created:** [May 20, 2015, 8:26am UTC](https://talk.remobjects.com/t/contributing-json-support-to-sugar/6219 "2015-05-20T08:26:59Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [May 19, 2015, 10:49pm UTC](https://talk.remobjects.com/t/contributing-json-support-to-sugar/6219/1 "2015-05-19T22:49:37Z")

</div>

> [@Creating Common Class Library for iOS and Android](https://talk.remobjects.com/t/creating-common-class-library-for-ios-and-android/6163/37):
>
> Is there a Sugar class that handles cross platform Json Parsing? If not, how can write one so that I can contribute it to Sugar on Github?

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.

---

<div class="post-metadata">

### Author: ![Salman](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@Salman](https://talk.remobjects.com/u/Salman)
#### Post date: [May 20, 2015, 5:33am UTC](https://talk.remobjects.com/t/contributing-json-support-to-sugar/6219/2 "2015-05-20T05:33:20Z")

</div>

> [@Creating Common Class Library for iOS and Android](https://talk.remobjects.com/t/creating-common-class-library-for-ios-and-android/6163/38):
>
> b ut someone starte working on it in the stable-feature-json

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

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [May 20, 2015, 8:24am UTC](https://talk.remobjects.com/t/contributing-json-support-to-sugar/6219/3 "2015-05-20T08:24:22Z")

</div>

> [@Creating Common Class Library for iOS and Android](https://talk.remobjects.com/t/creating-common-class-library-for-ios-and-android/6163/39):
>
> Is there something I can do to contribute?

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).

> [@Creating Common Class Library for iOS and Android](https://talk.remobjects.com/t/creating-common-class-library-for-ios-and-android/6163/39):
>
> Also when I checked Http.pas, I found that the language used to code it was different. What language is that?

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

> [@Creating Common Class Library for iOS and Android](https://talk.remobjects.com/t/creating-common-class-library-for-ios-and-android/6163/39):
>
> 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

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?

---

<div class="post-metadata">

### Author: ![Salman](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@Salman](https://talk.remobjects.com/u/Salman)
#### Post date: [May 23, 2015, 6:51am UTC](https://talk.remobjects.com/t/contributing-json-support-to-sugar/6219/4 "2015-05-23T06:51:04Z")

</div>

> [@mh](#):
>
> 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).

The problem with Json Parsing on .Net is that there are many options. We have the [JavascriptSerializer](https://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer%28v=vs.110%29.aspx) class on the web, and [JsonValue](https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh770289.aspx) on Windows Phone. Additionally, people like to use [Json.Net](http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_JsonConvert.htm) instead of the default json serializer so that’s the third option. And then there’s the new [System.Json](https://msdn.microsoft.com/en-us/library/system.json%28v=vs.110%29.aspx) 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?

> [@mh](#):
>
> I’d say start with fleshing to an empty API first, we can then review this, before you fill it. How does that sound?

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

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [May 23, 2015, 1:00pm UTC](https://talk.remobjects.com/t/contributing-json-support-to-sugar/6219/5 "2015-05-23T13:00:25Z")

</div>

We do have a partial JSON implementation here: [https://github.com/remobjects/sugar/tree/master/Sugar.Data/JSON](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)

---

<div class="post-metadata">

### Author: ![Salman](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@Salman](https://talk.remobjects.com/u/Salman)
#### Post date: [May 23, 2015, 5:42pm UTC](https://talk.remobjects.com/t/contributing-json-support-to-sugar/6219/6 "2015-05-23T17:42:36Z")

</div>

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?
