473,761 Members | 10,276 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

slightly more powerful JSON

Hello group,

I have been using JSON for a while and it has made many things a breeze.
However, JSON does not natively describe certain things like pointers
and custom types. I created a simple JSON extension that allows
cross-references, and I'm asking for your thoughts on a simple type system.

I've dubbed this variation RJSON (Red's JSON) for lack of a shorter
name. Here's how it works right now:

The JSON way to encode a few people might be :

{ "doug" : { "friends" : [ { "ryan" ] },
"ryan" : { "friends" : [ "doug"] } }

that is sort of odd since now doug and ryan's friends are not people,
but are instead strings. An RJSON encoder recognizes object equality
when serializing and encodes the friends with cross-references:

{ "doug" : { "friends" : [
xdecl(0, { "friends" : [ "doug"] } ) ]
"ryan" : xref(0) }

that allows more objects to be better described than in pure JSON. more
sophisticated relationships are allowed, including things like circular
references.

Now for a type system. YAML has a fairly effective type system, and
when I used Ruby I liked how easy it was to dump custom types. YAML is
not ideal for the browser because it requires more extensive parsing.
JSON, on the other hand, is great in the browser because it can be
evaled. The goals of the type system are a syntax that is
Javascript-compatible but simple enough to parse pretty easily. I would
like to combine the quick ability to dump objects that YAML has with the
evaluation speed of JSON.

so consider we have a object type called Person:

function Person(name, email) {
this.name = name;
this.email = email;
}

[ xtype("Person", { "name" : "Doug", "email" : "theeyesofmice@ gmail" } ]

the type that is the first argument to xtype is a string descriptor of
the type. the parser can then, for example, look up the type string in
a table that maps type strings to handler functions. A handler that
will initialize person might look like

function(obj) { return new Person(obj.name , obj.email) }

It doesn't have to be a table lookup, though.. it can be any function.

Here's the unsafe parser I currently use:

function marshallRjson(t ype, arg) {

var lookupTable =

{ 'Person' : function (obj) {

new Person(obj.name , obj.email);

} };

if (lookupTable[type]) {

return lookupTable[type]();

};

};

function evalRjson(rjson Text) {

var xrefTable = { };

var xtypeWithObject s = { };

var xdecl =

function (name, value) {

return xrefTable[name] = value;

};

var xref =

function (name) {

return xrefTable[name];

};

var xtype = marshallRjson;

return eval('(' + rjsonText + ')');

};

All this code is, basically, is introducing the ability to call a few
functions inside would-be JSON code. The real idea behind these
features is sharing object representations between an application server
and client in a more sophisticated way than easily possible right now.
neat? not? suggestions?

thanks for your time,
Red Daly
International Object Database
[Aside] This is probably one of the less interesting webby things I'm
working on right now. Cooler is an alternative object system based on
generic functions and class-based inheritance. I am just starting to
look into the applications of lazy evaluation for web programming.

An example implementation of an encoder for RJSON is available here:
http://suavescript.googlecode.com/sv...src/rjson.lisp
Jan 3 '07 #1
1 1730
Red Daly wrote:
The JSON way to encode a few people might be :

{ "doug" : { "friends" : [ { "ryan" ] },
"ryan" : { "friends" : [ "doug"] } }
Does the above evaluate correctly in a browser? I would think it would
need to be:

{ doug : { friends : [ "ryan" ] },
ryan : { friends : [ "doug" ] } }

Cheers
Chad
Jan 3 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
2702
by: G Matthew J | last post by:
http://htmatters.net/htm/1/2005/07/evaling-JSON.cfm This is more or less in response to Mr Crockford's admonition a few months ago, "fork if you must". Ironically, although in that usenet post he calls what I am suggesting "brittle", his own Javascript JSON parser is not valid JSON, but rather conforms to my proposed variation on JSON!! With an identifier prepended to the front of the JSON block, and function literals as values: see...
20
6881
by: Luke Matuszewski | last post by:
Welcome As suggested i looked into JSON project and was amazed but... What about cyclical data structures - anybody was faced it in some project ? Is there any satisactional recomendation... PS i am ready to use JSON as data/object interchange when using AJAX and my J2EE project - because it is easier to traverse the JavaScript object than its XML representation (so of course may argue).
2
3324
by: ChrisO | last post by:
I've been pretty infatuated with JSON for some time now since "discovering" it a while back. (It's been there all along in JavaScript, but it was just never "noticed" or used by most until recently -- or maybe I should just speak for myself.) The fact that JSON is more elegant goes without saying, yet I can't seem to find a way to use JSON the way I *really* want to use it: to create objects that can be instantated into multiple...
23
3213
by: dhtmlkitchen | last post by:
JSON We all know what it is. In ECMAScript 4, there's a JSON proposal: Object.prototype.toJSONString String.prototype.parseJSON The current proposal, String.prototype.parseJSON, returns an object.
0
9531
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8780
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7332
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5229
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.