I've added a haxe.JSON class to SVN trunk, you can test it with both
2.08 and SVN build here :
http://haxe.googlecode.com/svn/trunk/std/haxe/JSON.hx
So far I've only implemented JSON.stringify (with no optional
parameters). It's a complete rewrite but I've based some behaviors on
hxJson2 haxelib library.
I'm interested in testing/benchmarks/suggestions.
Please note that for flash 10.3+ we will use native JSON flash api, and
for JS we will use global JSON api if available at runtime. You can
force usage of haxe implementation by compiling with -D haxeJSON
Best,
Nicolas
A quick comment: since it is Xml, not XML, should it be Json instead of JSON?
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
I've thought about it but all the native API uses JSON...
Best,
Nicolas
'\\'.code which syntax is this? I haven't seen it before? is code a
function !? There is no using. Or is it a special trick built into the
compiler?
About parsing: For neko regex are fastest. I did some benchmarks ago -
it was still a lot slower than a .fastCharAt implementation could be
(using JS, CPP backends ..) One of the problems I (and Stephane's parser
combinator library encountered) was that there is no efficient way to
apply a regex at char position X. eg PHP provides offset feature.
Maybe it should be added to regex class
See my attempts here:
https://groups.google.com/group/haxelang/browse_thread/thread/313c42f3349af6a5
Also I think we should fix the UTF-8 issue I talked about earlier first.
I've made some progress - I'm pretty sure that the way to go is "keep
thing simple" - which means only allow char8 or unicode strings at the
same time - because HaXe allows var s += "abc" like syntax.
Its what the CPP backend does anyway. I haven't had time to finish the
patch yet :(
However I had about 120MB of json log files I tried processing - and
fastest was using PHP - it was fast to write and ran fast (because
json_decode in PHP is native C function).
anyway for different target different strategies are required unless non
optimal speed is fine (which probably applies to many web related
systems).
Marc Weber
By extension of that argument, Xml should be renamed to XML in haXe :P
But more seriously, the std lib uses mixed case for acronyms: Http,
Xml, Rtti, Mysql, HtmlEditor, Gc.
It takes a while to get used to, but its ok. Also JSONHTTPAPIURL
doesn't really read that well :D
But most importantly, I think it should just be consistent, so I
"vote" for `Json` ;)
As for haXe 3 I suggest SHA1 > Sha1, JSGenApi > JsGenApi, and also one
might rename all that flash api stuff with @:native (although I think
it's ok to accept that Adobe has it's own personal taste).
Regards,
Juraj
Yes, it' s special trick : it will compile into the corresponding
character code integer. I've added it to
http://haxe.org/manual/tips_and_tricks
Best,
Nicolas
I'm mostly interested in having a standard standalone "compatibility"
version that runs fast enough on all targets and is easy to maintain.
We will of course use faster native implementation when it's available.
Best,
Nicolas
There is also a native PHP extension for JSON decoding and encoding and
as far as I remembered it worked nicely together with hxJson2 (or
json4haxe, an older attempt of mine to make hxJson2 more hax'ish -
https://github.com/TheHippo/json4haxe, unfinished).
Philipp
2012/2/19 Heinz Hölzer <heinz....@googlemail.com>:
From there, we can investigate all sorts of native possibilities to
speed things up, but I don't think this is really critical at the
current stage. For now we shouldn't forget that having a working
solution with a stable API is infinitely better than what we had so
far and provides all the room for performance improvement that we may
need.
Regards,
Juraj
If you would like the haXe class to work with non-standard JSON (like
identifiers instead of strings), you need to stick with the haXe
implementation to get the same behaviour on all platforms.
Basically there are two possible ways to go:
a) Just pure standard JSON with fast speed through native functions if
available
b) Fanzy JSON alike format encoder / decoder, with a pure haXe
implementation
I personally would prefer to go with a). It fits for most appliances and
if you want something besides the standard you always could use a library.
Philipp
Fixed, the file is now :
http://haxe.googlecode.com/svn/trunk/std/haxe/Json.hx
Best,
Nicolas
I tried using json_encode for PHP but it converts arrays into the
following { null : [<array content>], length : 2 } (because of haXe
wrapper ?). I guess the issue is reversed by json_decode : you don't get
proper haXe Arrays.
Any efficient way to deal with it ?
Best,
Nicolas
----------
class _hx_array extends ArrayObject implements ArrayAccess, IteratorAggregate {
var $»a;
var $length;
function __construct($a = array()) {
$this->»a = $a;
$this->length = count($a);
parent::__construct($a);
}
...
---------
Cheers,
Clément
Well, that's not what we want here : we need ["foo","bar"] ;)
Nicolas
Yes thanks that would be helpful. Fell free to complete haxe.Json with
optimized PHP implementation ;)
Best,
Nicolas
Followup : there is now Json.parse as well.
I'm interested in testing/benchmarks/feedback for the different platforms.
You can use -D haxeJSON to force the usage of the haxe JSON class
instead of using native one (on JS when available on for Flash 11+)
http://haxe.googlecode.com/svn/trunk/std/haxe/Json.hx
Best,
Nicolas
Best,
Nicolas