Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / What's the best way to structure this API-type-thing?

Author
Message
xyzz1233
17
Years of Service
User Offline
Joined: 18th Nov 2007
Location:
Posted: 12th Apr 2011 04:17
Hey everyone!
I'm currently in the process of developing a UI toolkit as a part of a larger project of mine. The idea is that this toolkit takes some input in the form of either JSON or XML and turns it into a user interface. So here's the question: Should users define their user interfaces using JSON or XML?

XML seems to be the most familiar to developers considering that most other UI markup solutions use XML, namely HTML and WPF/XAML. However, JSON would be easier to parse, I'd be able to directly import those data structures into my code for processing, instead of having to move elements the parsed XML to new data structures. Thus it'd just be easier to do it with JSON. Thing is, developers might get kinda irked that their UI is being defined in JSON. It's not the most readable or concise.

I then thought that JSON might not really be the way to go, but regular javascript where I can use constructors. This isn't really "safe" to parse (you'd have to use eval), but I'm not sure if that matters to me.

I'll give some examples of what I mean:

XML:


JSON:


JS:


Which one do you guys think would be the best to go with? I'm leaning toward #3 but all of them have their positive and negative aspects.
thenerd
16
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 12th Apr 2011 04:37
I agree with you, #3 seems the most appropriate. XML is more suited for tables and entities, because of the nesting and attributes as part of one line. JSON seems nice as a second choice, I've never actually used it though. Something you should think about, is, will the end result be generated, or typed in by hand. If it is generated, JSON would probably be better because it is more organized and "clean" to parse. If users are typing, javascript is easier to read...

JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 12th Apr 2011 05:01
Quote: "Thus it'd just be easier to do it with JSON. Thing is, developers might get kinda irked that their UI is being defined in JSON. It's not the most readable or concise."

That's funny, because I'd say that JSON is generally way more readable/concise than XML. QML is a markup language that is used with the latest version of QT and it looks a LOT like JSON.

Your mother has been erased by a mod because it's larger than 600x120
xyzz1233
17
Years of Service
User Offline
Joined: 18th Nov 2007
Location:
Posted: 12th Apr 2011 05:11
Quote: "I agree with you, #3 seems the most appropriate. XML is more suited for tables and entities, because of the nesting and attributes as part of one line. JSON seems nice as a second choice, I've never actually used it though. Something you should think about, is, will the end result be generated, or typed in by hand. If it is generated, JSON would probably be better because it is more organized and "clean" to parse. If users are typing, javascript is easier to read..."

No, this will be written by developers, not generated by any kind of tool. At least not now.

Quote: "That's funny, because I'd say that JSON is generally way more readable/concise than XML. QML is a markup language that is used with the latest version of QT and it looks a LOT like JSON."

Yeah, I agree, but this example is different. There are probably less characters in the JSON than XML if you eliminate whitespace, but the overall readability would obviously suffer if I did that.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Apr 2011 06:03
So you want to use JSON because it'd make it easier for you to develop? Look at who's going to use the toolkit and what's going to be easier for them. Even if it takes more work on your end, you should focus on what makes it better for the end-user, not the developer.

The Internet: Where men are men, women are men, and children are federal agents
xyzz1233
17
Years of Service
User Offline
Joined: 18th Nov 2007
Location:
Posted: 12th Apr 2011 06:10
I'm pretty sure that I'll actually be going with route #3.

About making things better for the users (or developers using the platform, rather), I think that's important, but I can always revise my code and the toolkit later. I have a really awesome and innovative idea and I want to be first to market with it.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Apr 2011 06:20
well you don't wanna release something that requires users to write in JSON then change it later to XML. Best to stick with the same one from the start.

The Internet: Where men are men, women are men, and children are federal agents
thenerd
16
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 12th Apr 2011 13:29 Edited at: 12th Apr 2011 13:29
Quote: "No, this will be written by developers, not generated by any kind of tool. At least not now."
In that case, I agree with you, javascript seems the best way to go for simplicity.

TechLord
22
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 16th Apr 2011 12:54 Edited at: 16th Apr 2011 13:14
For the Super 3D Game Platform User Interface/Level Creation, I'm using XML/LUA Combination (S3GXL). XML for definition, LUA for logic. I'm in favor of the XML solution as it is the most familiar to developers considering that most other UI markup solutions use XML, namely HTML and WPF/XAML. Also, there are a several Free XML Parser Libs available. I'm using irrXML, which is fast and easy to use. Here's an example of S3GXL:



Login to post a reply

Server time is: 2025-05-28 21:03:42
Your offset time is: 2025-05-28 21:03:42