-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replacing own JSON implemementation with Crockfords JSON parser #262
Comments
I would go with the naming @fabianmoronzirfas, is Crockfords implementation ExtendScript compatible? |
Yes it is. I think we also should keep the normal JSON object around and not only have dedicated functions for writing to disc and loading from disc or url |
+1 for Crockfords' JSON implementation! |
Ok, so what do we have now?
Is that correct? |
Yes and keep the JSON object in global scope I would say and so |
Wait, but I'm still not sure about keeping the JSON global object. I see no real advantage in keeping it (except for catching those copy paste JSON.stringify()/JSON.parse() commands, but I don't think it should be basil's job to polyfill standard Javascript functionality). But I am open to your opinions. |
I would vote for:
loadJSON()
saveJSON()
JSON.stringify
JSON.parse
Even p5.js simply points to the standard JSON object and does not bother introducing a wrapper.
|
Hm, yes, okay now I understand the reasoning a bit better. |
Yes. I would vote to kicked out b.json.encode and b.json.decode in favor of JSON.stringify and JSON.parse!
|
++ on kicking them |
Ok, fine with it as well. But we'll need to implement this with basil 2.0 then, since it will break backwards compatibility. |
Cool. Should we support JSONP like p5.js does? https://p5js.org/reference/#/p5/loadJSON (btw I'll be AFK for the next few days) |
No to JSONP! :) |
Good call. :) |
Why can’t we have both? They could both point to the same function. P5 peeps happy, DOM peeps happy. There is an obvious use case for both here but generally if there is a crossroad we should favor a translation from processing right? |
IMO we should be close to Processing and P5.js where we can but still keep in mind that we are in InDesign. My favorite solution is as @b-g proposed: loadJSON() |
Ok, I have implemented Crockford's // @include ~/Documents/basiljs/basil.js;
function draw() {
var url = "https://itunes.apple.com/search?term=basil&entity=song";
var myString = loadString(url);
var data = JSON.parse( myString );
inspect(data, {maxLevel: 3})
var jsonString = JSON.stringify(data);
inspect(jsonString);
} Now, I need to implement
Both correct? |
Awesome 🚀. I'll take it for a test ride tomorrow. Which version of the json parser did you use? |
Super!
✅
✅ |
Should be the most recent one. The reason why I implemented that now is that I tried the above API sample in my class yesterday and it did not work with basil's old (current) JSON parser. With Crockford's implementation it works now. |
Cool. Could we extract the json2.js part into its own file so we can update it automatic? |
I don't think that's necessary. |
But the latest commit on that file was 9 month ago. So there might be bug fixes or security issues with json |
While this might be true, I think it will be more work to implement an automatic updating than just updating this by hand every once in a while (last change to the actual code was more than 2 years ago). Having said that, if you are really motivated to implement an automated solution, I'm fine with it. I myself have neither the skills nor the time to do so. So, I will first prepare a manual implementation, and if you want to take this further afterwards, please feel free to do so. |
I took a different approach to reviewing this today. Started with writing some tests. You can see them here. https://github.com/basiljs/basil.js/blob/json/test/json-tests.jsx testJSONFromStringWithStrangeResult: function(){
$.write("JSON.parse('1.000000000000001') should give a result of ");
var parsed = JSON.parse('1.000000000000001');
$.writeln(parsed);
$.writeln("assert(JSON.parse('1.000000000000001') === 1.000000000000001) does...");
assert(JSON.parse('1.000000000000001') === 1.000000000000001);
} Actually this test should fail. The result is:
|
Actually not wired. InDesign can only do |
Removed that section from test with the last commit f78d422 |
This has been implemented via #328 . |
The new JSON functions have been working great! Wanted to ask if others thought it worth keeping Guessing CSV should get the same treatment, |
-1 keeping the decode functions LoadTable in p5 is pretty huge. I skimmed through the code recently. Do we need this? |
I agree we don't need |
Yes, that would be good. 👍 |
Sounds good – working on this right now (and adding simple
Question: We have the Currently:
Could be:
Allowing (soon):
|
Address all of this in #348 |
Yes, sounds good. We should remove the |
I would really like to removing this JSON decode/encode functions and replace them with Douglas Crockfords JSON parse/stringify maybe with an alias for stringify and parse or removing decode/encode.
The text was updated successfully, but these errors were encountered: