"new" JSON library fastJson

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: "new" JSON library fastJson

Post by mwieder » Fri Oct 09, 2015 12:07 am

Bob-

I'm don't think your isNumericalArray() function does what you want. It looks like you're just checking the first char of each key.
So keys like

0ThisIsZero
1001Nights

would return true.

A better filter might be

Code: Select all

filter pArray with "*[A-Za-z]*"
which will return tArray not empty for any non-numeric keys.

(Edited for typo)

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: "new" JSON library fastJson

Post by FourthWorld » Fri Oct 09, 2015 12:38 am

We can use the filter command directly on an array? Might be a documentation bug, as I'd always thought it would only work on the extracted keys of the array, and double-checking the Dictionary entry I didn't see mention of arrays as containers that could be used with filter.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: "new" JSON library fastJson

Post by mwieder » Fri Oct 09, 2015 12:45 am

Not that I know of. Sorry - I put my test code in the post by accident. The code in the function is

Code: Select all

   put the keys of pArray into tKeys
   filter tKeys with "*[A-Za-z]*"

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: "new" JSON library fastJson

Post by FourthWorld » Fri Oct 09, 2015 12:48 am

Damn - too bad, I was hoping I'd been missing some cool undocumented feature.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: "new" JSON library fastJson

Post by mwieder » Fri Oct 09, 2015 12:54 am

Yeah, I just tried, just in case it actually worked.



Nope.
Can't filter the keys or the element data.
Sorry.

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: "new" JSON library fastJson

Post by phaworth » Fri Oct 09, 2015 1:27 am

I'm finding that this library and a couple of others I've tried are returning an error when trying to parse the JSON used for the dictionary in LC8. Not much in the way of details, just a message that it failed instead of an array.

On my Mac, the file is in Applications/Contents/Tools/Documentation/html_viewer/resources/data/api/built_api.js. I don't know enough about JSON to figure out what's wrong with it so any guidance is welcome.

Pete

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: "new" JSON library fastJson

Post by phaworth » Fri Oct 09, 2015 1:43 am

I should also mention that I pasted the JSON into a couple of online JSON viewers and they were able to interpret it correctly.

Also, the JSON starts at line 2 of the file I mentioned.

Pete

pink
Posts: 272
Joined: Wed Mar 12, 2014 6:18 pm

Re: "new" JSON library fastJson

Post by pink » Fri Oct 09, 2015 11:47 am

another important thing to note is that "e" can exist in a valid number, so you can't just filter out all letters otherwise a number such as 2e+10 would get labelled as a string (it is valid as a number in both Livecode and JSON)
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

pink
Posts: 272
Joined: Wed Mar 12, 2014 6:18 pm

Re: "new" JSON library fastJson

Post by pink » Fri Oct 09, 2015 11:55 am

technically the dictionary isn't a pure json, it's javascript that uses a JSON as the definition of a variable "dictionary_data"

so the inability to interpret it makes sense, this JSON interpreter is only looking for a JSON and doesn't have any instruction to ignore irrelevant data
phaworth wrote:I should also mention that I pasted the JSON into a couple of online JSON viewers and they were able to interpret it correctly.

Also, the JSON starts at line 2 of the file I mentioned.

Pete
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: "new" JSON library fastJson

Post by phaworth » Fri Oct 09, 2015 6:38 pm

Hi Greg,
Right, Ali Loyd mentioned that. As mentioned, I am not familiar with json format but shouldn't lines 2 to -1 of the file be valid json? Line 1 is the javacsript var declaration.

As mentioned, I pasted those lines into a couple of the online json viewers that are available and they were able to parse it without a problem.

The one at http://jsonviewer.stack.hu for example produces a nice array type of display from it.

The one at http://codebeautify.org/jsonviewer has a Validate feature that says it's valid JSON and is also able to display a tree view of it and convert it to XML.

I guess I'm wondering what it is in the library that causes it to think this isn't valid JSON. Any help much aprecciated.

Thanks,
Pete

pink
Posts: 272
Joined: Wed Mar 12, 2014 6:18 pm

Re: "new" JSON library fastJson

Post by pink » Fri Oct 09, 2015 11:08 pm

Hi Pete,

I've been fiddling around with the help file and found the same problem... I'm not sure what the issue is. I've broken it into smaller chunks and been able to process them, but when I do the whole thing it doesn't work and doesn't provide any sort of error.

There are a lot of JSON arrays within that contain only one item. I do not know if there is anything to this, but Bob did have at least one instance where an array with a single element caused an error. This is wild speculation on my part... but I am definitely going to keep fiddling around with the help text to see what I can do.
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: "new" JSON library fastJson

Post by phaworth » Fri Oct 09, 2015 11:52 pm

Thanks Greg, I appreciate you trying to figure it out. I know enough about JSON that I noticed the single element arrays too but there are a lot of them and it seems the error doesn't occur until well after it's processed at least some of them.

This is probably a huge longshot but in my attempts to parse the JSON myself, it seemed that the last doc that was processed was the one with id 274. When I looked at the next id after that it had some strings set to "eof" (some upper case, some lower). It seems highly unlikely but could "eof" be confusing things?

bhall2001
Posts: 107
Joined: Thu Oct 30, 2014 3:54 pm
Location: Manchester, NH

Re: "new" JSON library fastJson

Post by bhall2001 » Tue Oct 13, 2015 12:00 am

Sorry, I was away on vacation through the long weekend and did not have reliable access to Internet.
Bob-

I'm don't think your isNumericalArray() function does what you want.
fyi- this is copied and pasted form the existing easyJson library. So this would be true with the existing library. I'm still scratching my head about isNumbericalArray(). Funny that you brought this up. I was planning to look at this particular function. I'll have a look and see what's going on with it.

Bob

Brahmanathaswami
Posts: 52
Joined: Mon Jun 24, 2013 4:10 am
Location: Hawaii
Contact:

Re: "new" JSON library fastJson

Post by Brahmanathaswami » Tue Oct 13, 2015 10:23 pm

if the LibJson you were working with was the one done by Mark (who has since go to the land of angels) ... it's very old and we had trouble with it recently, both in a mobile app and on the server. It does not appear to be handling Unicode the way we expect.

We started using Andrea Rosek's JSONlib and it is performing better. I'm a bit out of my depth so cannot comment much more than that. RevOnline had Andrea's stack... I can't access RevOnline right now as the IDE says the server is offline... so don't have a URL.

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: "new" JSON library fastJson

Post by phaworth » Thu Oct 15, 2015 1:13 am

Hi Greg,
I've been continuing to work with fastJSON and the LC8 dictionary file. I decided to hand each json element off to jsonToARray as a separate thing which worked better, no error, but then parsing the following never returned from jsonToArray and the script stopped executing, no error messages. Maybe there's some malformed json in there?
{ "id":"708",
"name":"rtftext",
"display name":"RTFText",
"type":"property",
"syntax":[
"set the RTFText of [<chunk> of] <field> to <RTFString>"
],
"display syntax":[
"set the RTFText of [<i>chunk</i> of] <i>field</i> to <i>RTFString</i>"
],
"associations":["field"],
"summary":"Specifies the contents of a <field>, with its text <format|formatting> represented in <RTF|RTF format>.",
"introduced":"2.0",
"OS":["mac","windows","linux","ios","android"],
"platforms":["desktop","server","web","mobile"],
"examples":[{
"script":"set the RTFText of field \"Stuff\" to URL \"file:New Stuff.rtf\""
},{
"script":"put the RTFText of field \"Destination\" into URL myURL"
}],
"value":[{
"name":"value",
"type":"",
"description":"The <RTFText> of a field is a string."
}],
"description":"Use the <RTFText> property to import and export text in RTF format.\n\nThe <RTFText> property is a representation of the styled text of the field in RTF format.\n\nSetting the <RTFText> of a field (or a chunk of a field) sets both the text contents and the font, size, style, and color attributes corresponding to the information in the <RTFString>. Any other formatting controls in the <RTFstring> are ignored.\n\nThe <RTFText> property interprets the following RTF formatting controls:\nColors:\\cf, \\colortbl, \\red, \\green, \\blue, \\highlight\nStyles:\\plain, \\b, \\i, \\ul, \\ulnon, \\strike, \\dn, \\up\nFont and character set: \\fcharset, \\ansi, \\mac, \\pc, \\pca, \\u, \\fonttbl, \\f, \\fs\nOthers:\\header, \\par, \\line, \\tab\n\nGetting the <RTFText> property reports a string consisting of the text of the field (or chunk of a field), with any font, size, style, and color properties embedded in the text in the form of RTF control words. Unicode text is supported.\n\nParagraphs with a non-empty listStyle are appropriately marked in <rtfText> using both the (legacy) pn family of paragraph numbering tags and also with the new listtable tags.\n\nBy using both sets of tags a reasonable degree of interoperability is achieved with both TextEdit (and other Cocoa applications) on Mac, and Word and WordPad on Windows. \n>*Note:* Unfortunately, OpenOffice does not have particularly good rtf import / export capabilities (it doesn't even round-trip correctly through itself!) and thus copying / pasting of lists between LiveCode and OpenOffice will not work reliably or correctly.\n>*Important:* Because the RTF standard does not include the box, threeDbox, and link styles supported by LiveCode, the <RTFText> property does not necessarily include all information necessary to reproduce the style information in a chunk. To export and re-import field information without losing any style information, use the htmlTextproperty instead.\n\nFor technical information about the RTF format, see the article at <http://msdn.microsoft.com/library/en-us ... tfspec.asp>.",
"references":{
"property":["HTMLText","foregroundColor","dragData"],
"keyword":["field"],
"function":["charToNum"],
"glossary":["format","RTF"]
},
"tags":["text processing"]}
\

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”