JSONItem replacement

I’m just about finished with a drop-in replacement for JSONItem. It’s all Xojo code and emulates all features and functionality of the native class, except:

  • It’s around as fast, if not faster, to create and load.
  • It handles Unicode characters correctly for both values and, in objects, names.
  • It throws an exception if you try to add a value it can’t handle rather than waiting until you call ToString.
  • It is something like 40 times faster when generating large JSON strings. (That is not a typo.)

The last point is why I undertook the project at all. In my test case of 10,000 objects, it takes the native class 4.7 seconds to render a string. It takes my class around 106 milliseconds.

To use it, you’d find and replace all occurrences of JSONItem with JSONItem_MTC, then drag the class to your project.

If there is interest, I will post this as an open-source project on my web site when I get back from vacation. Is there interest?

Very generous offer! Yes, making it open source (on github?) would be highly appreciated.

Github!

Is it faster than my JSON plugin class?

Another thing: Please talk to Xojo engineers about it. Because if it’s so fast, why not give it to Xojo Inc. and let it become the new implementation of JSONItem class?
That would speed up all the web stuff instantly.

[quote=120558:@Christian Schmitz]

Another thing: Please talk to Xojo engineers about it. Because if it’s so fast, why not give it to Xojo Inc. and let it become the new implementation of JSONItem class?
That would speed up all the web stuff instantly.[/quote]

+1
And Kem’s name should be mentioned in the docs for this contribution.

An additional version on github or Kem’s website would be great also. So we can individually adapte his code if necessary.

Many thanks to Kem if this comes true.

By the way, Kem do you handle duplicate key names well?

This would be awesome Kem!

I like the idea of perhaps Xojo being able to build it in if compatible, as long as it has a BSD, MIT or other permissive license there’s a chance they’ll look at it.

@Kem Tekinay - That would be great. I could embrace JSON again instead of cringing :slight_smile:

I didn’t test that. I’d suspect not, but I could certainly give it a try.

[quote=120558:@Christian Schmitz]Another thing: Please talk to Xojo engineers about it. Because if it’s so fast, why not give it to Xojo Inc. and let it become the new implementation of JSONItem class?
That would speed up all the web stuff instantly.[/quote]

I plan to release it as open source and free to use by anyone for any purpose, including by Xojo. (That would be neat though. :slight_smile: )

Yes, I used the same technique as in my case-sensitive Dictionary, i.e., names are converted to UTF-8, then hex-encoded.

I’m interested in speed json string generation.
Actually I’ve an extension to JSONitem that is far faster than the Xojo one.

This is cool. I did not even know there was a class built-in to Xojo for this. I have worked with JSON text generating and I did not use a class. Good to know about your project Kem, thanks.

Excellent work Kem and thank you for your commitment to the Xojo community!

Is there an existing Interface like “StringProvider” or the like? For example, suppose I have an object that can be converted to a string, and I want the world to know. Is there some interface for that purpose?

If not, would it be useful to add that and have my class recognize it? It would mean adding two items to your project instead of the one.

It’s usual the objects that can be converted to string have a .ToString() method.

What’s the best approach to find the existence of a method in a object and invoke it in Xojo?
The ToString() probably could be part of some kind of Serializable Interface.

And then I heard the voices in my head say, “but if it can be converted to a string, why wouldn’t it just be added as a string?”

I agree that a serializable interface would be useful, but I won’t do that as part of this project.

Not following. You mean:

Dim o As New MyObject
Dim s As String = o // ???

In contrast to:

Dim o As New MyObject
Dim s As String = o.ToString()