I am currently working on one of my Spotlight Search Prompt based Projects which uses the dataType JSON.
I decided to use a .pkg (Package-) File for all of them to store all Resources in a Subfolder structure inside the Package based on the data providing Macro.
The Package is stored in my Dropbox for sync between my Macs and defined in a Global Variable called DND__sspMacroResourcesPackagePath .
For each of my "SSP - Main Macros" I use this Variable for building a Source based on local Variables - like so:
The magenta colored Variable Local__sspDataFile holds the Path for the JSON File inside the Package based on the Macro.
In this Case the Path inside the Package is:
The Variable Local__sspDataFullPath then uses the Variable DND__sspMacroResourcesPackagePath & the Variable Local__sspDataFile for building the full Resource for the Variable sspData .
If I use this approach - I get this Error from the Spotlight Search Prompt Macro:
The JSON itself is working but since it contains currently more than 2300 lines I decided that the Macro should use the JSON as file because it will grow in size.
Here are two Screenshots of the Prompt in action with the JSON as Text inside the Macro:
Without seeing all of your code, I hesitate to suggest a solution. However…
In this step,
you are putting the path to your JSON file into variable sspData. I suspect that what you want in sspData is the contents of that file, not the path to it. If that's the case, use the "Read a File" action.
It's hard to tell without looking at the JSON itself. But since you're new to JSON, here's my guess:
When you set a JSON value, it needs to be properly "escaped". For example, consider this Dictionary:
Since the "Value" has question marks in it, it has to be encoded like this in JSON:
{
"Key3": "Click the Help button (the \"question mark\") for more information."
}
This happens automatically for you if you use something like KM's Set JSON Value action. But if you built the JSON string by hand, you probably didn't encode it properly.
So my guess is that maybe there's an unescaped quote (or something similar) right before it barfs on the "/".
Your suggestion was absolutely right !! You nailed it !!
I was so confused about the Parse error and not nowing how to fix it that I totally forgot about the possibilities with the "Read a File" action. I even forgot that this Action exists ....
Sometimes it is the simple things you don't even think of.... thanks for that...
I even changed my Macro to use the "Read a File" action - and it works like a charm now.
I am building the JSON by hand using snippets - my knowledge is not at the level i need to build an entire JSON array using KM yet.
For Validation and viewing how many mistakes i've made I use a very handy Application named DevUtils.
I am sorry that your guess was not right - but you even helped me by the fact that I totally forgot about the possibility to use double quotes instead of just single ones in a JSON Value String when I escape them....
I have to laugh - as I scanned the sentence above, my mind read it as "I've made a very handy Application...", and when I looked at it, I thought "WTF? I thought he said he was just learning JSON!" A second look showed that it was an app you use, not one you made.
It looks very cool. I would think it would have the ability to automatically "escape" a string for inclusion in a JSON string.
Your mind was really thinking that I am the Developer behind DevUtils ? - Very funny ...
I know something like that very well. Sometimes you're reading something and your brain has it's own message behind that.
Yeah. It's a very cool Application... and it has a lot of handy tools in it ...
I've not tested that but I think that you're right and it should escape Strings automatically.
But in such a case I try to do the opposite way and look for properly escaped strings during my writing of code because my brain is focused on the Thing I am writing and and scans for the right syntax color at the same time...
Thank you Dan for providing this .... I took a quick look at Your new Macro Post. Seems like a very handy tool to have - as always when you post macros.
I don't know how many Stuff i have only from You (maybe 45 ore more Macros - maybe all ?!) - but I will definetely take a closer look at this new stuff later the next few days when I have time.
Thanks for mentioning that - it makes me feel good. For me, I'd say the same thing about @ccstone's stuff, so it's good to know I'm paying it forward.
I will definetely take a closer look at this new stuff later the next few days when I have time.
Don't feel obligated. Personally, I hate it when I feel obligated to look at something someone posted. I just figured there might be other people who might benefit from it.
No, of course not ... I am thinking the same way like you ... but here is the Thing - I think it is worthit for me to take a closer look so that I can figure out how I can use this in my json codin workflow.