bhall2001 / fastjson Goto Github PK
View Code? Open in Web Editor NEWA Livecode library for JSON encoding and decoding to and from Arrays.
License: MIT License
A Livecode library for JSON encoding and decoding to and from Arrays.
License: MIT License
The private function called isNumericArray is returning false for very large numeric arrays. The RegEx is failing to extract the keys. Tested with 500k worth of response in a single numeric array. Maybe its our LiveCode Server engine that can't use that RegEx expression.
Replacing that filter call with a slower loop will make this work and doesn't impact much on performance.
I wanted to post this as an issue because it may be an issue for others. I have a couple of quick fixes, but I am not 100% sure they need to be implemented so I am not going to create a pull request. For CouchDB the empty array is important, I believe that it also is for MongoDB. I am not sure about other uses.
Here is an example of what I am trying to produce (this is a user record for CouchDB):
{"name":"madpink","password":"trustno1","roles":[],"type":"user"}
"Roles" needs to be an array, and can only be full of strings or completely empty. Closest I can get is this script:
put "madpink" into tData["name"]
put "trustno1" into tData["password"]
put "user" into tData["type"]
put empty into tData["roles"][1]
put jsonFromArray(tData) into tJson
This is the result:
{"type":"user","password":"trustno1","roles":[null],"name":"madpink"}
However, this errors out. For the time being I just have the following to my own script:
replace "[null]" with "[]" in tJson
Needless to say, the reverse process is also a problem, so I added this step before processing a JSON into an array:
put "{""e&1"e&":null}" into tEmpty
replace "[]" with tEmpty in tJson
Now that they're built in, is it time to deprecate the library?
on an iOS device, this complete locks up the program... here's what happens...
in this instance, the response from the site is NOT a JSON, but is instead a 404 error
the problem seems to come with line 227:
put sJson[n-3] & return & sJson[n-2] & return & sJson[n-1] & return & sJson[n] & return & sJson[n+1] & return
in the Livecode IDE, this causes the message box to open up and display some characters, but in a compiled iOS app, everything freezes when it gets to this point
removing this line fixed the problem for me, as the next step is simply to return false
not sure what that line was meant to do...
from Livecode Dictionary JSON...
...
"type":""
...
Having an empty string is causing a significant performance issue until Livecode is quite and re-launched.
There seems to be a problem when jsonToArray() tries to parse an empty JSON object.
Example
For the following JSON
{"data":[{"pk_customer":"123","portalData":{}}]}
After running
put jsonToArray(theJson) into tResult
return arrayToJson(tResult)
We get
{"data":null}
However, if we run the same code for the slightly amended JSON
{"data":[{"pk_customer":"123","portalData":{""}}]}
We get
{"data":[{"portalData":null,"pk_customer":123}]}
According to JSONLint {}
is valid JSON.
Obviously this issue is easy enough to work around using
replace "{}" with "{" & quote & quote & "}" in theJson
Thought I'd at least mention it here even if it doesn't get fixed someone might need the easy workaround in the future.
Hey Bob,
I'm making a bunch of changes to the library and wasn't sure if you were still interested in updating it.
So would you prefer I make a pull request my changes, or would you prefer I fork it and maintain on my own? Currently, Ive added my modified version to my CouchDB lib.
The changes I've been making include:
-maintaining the sequence of a JSON array in order of the numeric array it is based on
-adding an option for inserting null into a JSON array when the numeric array it is based on has gaps
-changing the "keepNumeric" option to a script local variable
-adding a "set local" type command for these options instead of passing as params
I have a few other changes as well I'm working on.
Let me know if you want me to pull or tell me to fork off ;)
Any JSON string that starts with [ does not work in my tester script. Not sure if this is a problem with the sample stack or with the library. Getting this down so I remember to investigate it.
When decoding a json back into an array the library is missing all forward slashes. So your array values are filled with stuff such as \/
instead of /
While working on the Livecode Dictionary JSON file, an error was discovered in the Parser where the following JSON is not being parsed correctly by the Tokenizer.
...
"name":"-",
...
Tokenizer returns a "token" of "-,". This results in all data after this point being errant.
The private jsonValue() function is escaping a variable called pText
in its default case when the variable should be pValue
. this leads to corrupt json full of newlines and other non-conformant stuff.
Livecode returns true for numbers that start with "0". fastJson needs to catch this on export and turn these numbers into a string.
JSONlint report mal formed data. Found the issue that a dog name "Infinity" is having their name converted to a "number" called infinity. Interesting...
JSONlint does not like numbers that start with 0. Need to convert all numbers that start with a 0 to a string.
From forums.livecode.com
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.