JSONItem replacement

So I guess the answer is no. :slight_smile:

Right, you’d use o.ToString. My point is, there is no need for JSONItem_MTC to do that for you internally.

Currently, without the serialization power for the Xojo objects, I believe you should just ignore this part. You just need to mimic the JSONItem. Never tried to pass an object. Will try just to see what happens. :slight_smile:

Weird. It accepts an oJson.Append() and breaks the oJson.ToString() raising an exception of Type Mismatch. :stuck_out_tongue:

Yes. My class will throw the exception when you try to add the object instead.

But as an replacement, shouldn’t it had to mimic even it’s idiosyncrasies?
Or you intend to be a: “replace it”, but notice that are differences you must be aware: [follow the list].
(That said, I agree with you, I would prefer an exception putting the unacceptable values in.)

The latter. But if you look again at my original post, that’s the only major difference, and it’s a pretty minor one at that. I just feel this is better design.

(If there were a way to force a compiler error instead, I’d have done that. Alas, since Nil is a valid value, there isn’t.)

The other place where it won’t mimic the native is in the handling of Unicode characters within a string.

That’s a big omission Kem. JSON strings are UTF8. If you don’t do this users in other countries where diacriticals are used are going to have never ending trouble. For instance, how does your class handle résumé?

I think a better question is… Does the JSON spec handle duplicate key names?

Misunderstanding. It’s the native class that doesn’t do it right at the moment. Mine handles it correctly.

I’ll file a bug report at some point.

The official specs do not state one way or the other, in fact, it seems to indicate it is up to the application generating/consuming the data to make the best choice.

In Python and Ruby, the last man wins. i.e.

{ "a": "123", "a":"456", "a":"789" }

When you access “a”, you’ll get 789.

Technical point: the encoding of JSON strings isn’t quite real UTF-8. It is the same for the BMP (up to &uFFFF), but has a different way of handling the astral planes from &u10000 up.

[quote=120718:@Kem Tekinay]Misunderstanding. It’s the native class that doesn’t do it right at the moment. Mine handles it correctly.

I’ll file a bug report at some point.[/quote]

I realize this came across a little harsh. What I meant was, my understanding of the JSON standard is that Unicode characters (what I interpret to mean code point > 127) should be encoded. The native class does not do that, but perhaps it’s not strictly necessary.

Greg, to answer your question, this is how the native version outputs that string:

["résumé"]

My class does this:

["r\\u00E9sum\\u00E9"]

Perhaps there is no need for that encoding, in which case I’ll make it an additional preference property that defaults to the native way.

Great work as always kem!

That’s what I did.

[quote=121000:@Kem Tekinay]I realize this came across a little harsh. What I meant was, my understanding of the JSON standard is that Unicode characters (what I interpret to mean code point > 127) should be encoded. The native class does not do that, but perhaps it’s not strictly necessary.

Greg, to answer your question, this is how the native version outputs that string:

["résumé"]

My class does this:

["r\\u00E9sum\\u00E9"]

Perhaps there is no need for that encoding, in which case I’ll make it an additional preference property that defaults to the native way.[/quote]
I remember this coming up and doing some research about what needed to be encoded and what didn’t, but I don’t specifically remember what the answer was (and my computer is 150 miles away)

Well I’m fine with this solution. It dropped my ToString time even further. :slight_smile:

Kem
Can it set a value as well? ie same as

JSONItem.Value ( Name As String, Assigns Value As Variant )
Sets a named child’s value.

Yes, all of the native functions have been duplicated. If I missed any, it was an oversight.

Posted to GitHub:

https://github.com/ktekinay/JSONItem_MTC