Skip to content
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

JSON validation fails during compilation for JSON variables with (unquoted) number fields #136

Open
twilsonco opened this issue Nov 25, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@twilsonco
Copy link

twilsonco commented Nov 25, 2023

In my first attempt at rewriting a ShortCut as a JellyCut (this ShortCut for ChatGPT API use), I've encountered a bug with JellyCuts validation of JSON arguments, which is rejecting valid JSON strings that contain (in this case) number fields (unquoted), causing compilation to fail with "Compilation Error on line 6: Unable to find valid JSON", but only when the JSON being evaluated is from an existing Dictionary variable.

This validation is performed, for example, when using the dictionary() or downloadURL() functions, both of which take JSON variable or JSON string as arguments.

Interestingly, it won't reject the valid JSON string if it's hardcoded, so the following JellyCut code compiles and the resulting shortcut works:

import Shortcuts
#Color: red, #Icon: shortcuts 

dictionary(json: {"string": "value", "number": 1.0}) >> TestDict
showResult(text: "${TestDict}")

But, when the JSON being evaluated is a variable, the validation fails. So this code fails:

import Shortcuts
#Color: red, #Icon: shortcuts 

dictionary(json: {"string": "value", "number": 1.0}) >> TestDict
showResult(text: "${TestDict}")
dictionary(json: "${TestDict}") >> TestDict2
showResult(text: "${TestDict2}")

giving the error: "Compilation Error on line 6: Unable to find valid JSON" which is this line:

dictionary(json: "${TestDict}") >> TestDict2

Version/Device info. iPhone Mini 13, iOS 17.1.1, JellyCuts v1.4.1(5)

Also posted in Discord #issues-bugs

bad_json.jelly.txt
good_json.jelly.txt

@twilsonco twilsonco added the bug Something isn't working label Nov 25, 2023
@twilsonco
Copy link
Author

Cloned Open-JellyCuts (along with submodules), and searched for the error thrown above Unable to find valid JSON but it doesn't come up. I have zero experience with Swift so it'll take some digging before I can make much progress. Guess I'd start here?
CleanShot 2023-11-25 at 16 41 44

@ActuallyTaylor
Copy link
Member

Thank you for the comprehensive review of the issue! Right now, JSON usage in the App Store version is very finicky. The Open-Jellycuts version fairs much better but still has its own issues.

As for the issue you are seeing, from what I can tell, it is not a currently supported use case.

But, when the JSON being evaluated is a variable, the validation fails. So this code fails:
dictionary(json: "${TestDict}") >> TestDict2

When the above code is compiled, the Jelly compiler will not paste the value of the dictionary in to validate it as a string. I believe this bug appeared when I reworked how variables can be typed out, which lost the ability to use them as dictionaries. As of right now, there is not yet a way to fix this on the App Store version. I would gladly add you to the TestFlight version, which is where I will focus future fixes.

@ActuallyTaylor
Copy link
Member

ActuallyTaylor commented Nov 25, 2023

and searched for the error thrown above Unable to find valid JSON but it doesn't come up

The reason nothing is showing up is that the App Store version is not running the Open-Jellycore parser yet. When I get through finals season, I will be taking a bit to finish up Open-Jellycore / Jellycuts

@twilsonco
Copy link
Author

Understood, and thanks for the quick response! I'm relieved to see that development is ongoing, and not at all surprised at the issues due to App Store and other iOS limitations. Not my area of expertise, but I empathize with devs in Apple's ecosystem.

Side note: Now that I see development is an ongoing effort, I'll report another issue I found where foo.get(keys) for a dictionary variable seemed to not be returning a list of keys as expected. In that case an easy work around was to use keysFrom() instead. I'll put together and submit a MWE for that as well. Though I'll wait to confirm it happens with the TestFlight version so that I can include that context with the bug report.

@twilsonco
Copy link
Author

twilsonco commented Nov 26, 2023

Ok, I'm up and running on the TestFlight version (with another purchase of the Pro unlock, you crafty devil!), and the JSON issues aren't alleviated. Now, running a slightly modified example for dictionary() from the docs also fails:

import Shortcuts
#Color: red, #Icon: shortcuts

dictionary(json:{"name":"Taylor"})

Throws (approximately, this is using OCR since I was unable to select text from the console):

0:3 - ERROR (identifier content: (identifier_content))
(parameter_list_item item: (identifier content:
(identifier_content))) (ERROR) (parameter_list_item item: (string text: (string_chars))) (ERROR)
(parameter_list_item item: (string text: (string_chars)))
(string_chars)

  • Check your syntax in the surrounding area.

I'm happy to troubleshoot, if it helps.

@Grim73
Copy link

Grim73 commented Jul 11, 2024

having the same issue trying to variable-ize my Bearer token in a downloadURL function, I assume this is still a WIP?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants