Jump to content

Script filter - What to do when the JSON str is too long?


Recommended Posts

This is a workflow for filtering notes in Tinderbox. I have an applescript that will collect all the notes in the file with the URL and assemble it in a JSON format that Alfred can ingest. 

 

Example:

 

{ "items" : [{
					        "title": "Tinderbox-Acadêmico",
					        "subtitle": "",
					        "arg":  "tinderbox://Tinderbox-Acade%CC%82mico?view=outline+select=1618577108;",
					        },
{
					        "title": "TbxConfig",
					        "subtitle": "",
					        "arg":  "tinderbox://Tinderbox-Acade%CC%82mico?view=outline+select=1617846680;",
					        },
{
					        "title": "Hints",
					        "subtitle": "",
					        "arg":  "tinderbox://Tinderbox-Acade%CC%82mico?view=outline+select=1616867062;",
					        }
            ]}

 

I am using a script filter and the problem is that the whole string is 270.000 characters long, but Alfred truncates it at approx. 200.000 and never displays any result.

 

Is there any way to get this to work and still use Alfred to filter the results?

Edited by Bernardo_V
Link to comment
  • Bernardo_V changed the title to Script filter - What to do when the JSON str is too long?

I'd report it as a bug if I were you. There was a similar limit on STDERR (debugger messages) that was removed several years ago.

 

That said, it wouldn't surprise me if it's a deliberate limit for performance reasons: 200kB is a lot of items.

 

In terms of immediate solutions, you could do the filtering in your Script Filter instead of letting Alfred do it, so you aren't returning as many items to Alfred.

Link to comment
28 minutes ago, deanishe said:

Might be an encoding issue, then? @Bernardo_V Have you tried saving the JSON as ASCII (i.e. escaping all non-ASCII characters).

 

I did. The content doesn't seem to matter. Alfred truncates it at the precise same location every time (that is, after 200.094 characters).

 

6 hours ago, deanishe said:

In terms of immediate solutions, you could do the filtering in your Script Filter instead of letting Alfred do it, so you aren't returning as many items to Alfred.

Can you think of any workflow that I could look into to adapt for my situation? I was also thinking that it would be a good idea to build a cache so that the search is not performed every time.

 

3 hours ago, Mr Pennyworth said:

Alfred loads it correctly without truncation.

 Thanks, I will look into it to se if there is an applicable solution for me there.

Link to comment
2 hours ago, Bernardo_V said:

The content doesn't seem to matter.

 

The fact that Alfred accepts Mr Pennyworth's 10x bigger file suggests that size isn't the issue. Especially as you say you're using AppleScript, which is notoriously poor at generating JSON.

 

Please upload a file that triggers the issue somewhere (Dropbox?) and post a link if you'd like us to help figure out what the issue is.

 

Without that, we're just guessing, which is a waste of everybody's time.

Edited by deanishe
Link to comment
On 4/17/2021 at 11:36 AM, deanishe said:

The fact that Alfred accepts Mr Pennyworth's 10x bigger file suggests that size isn't the issue. Especially as you say you're using AppleScript, which is notoriously poor at generating JSON.

Indeed and that proved to be the case.

 

For future reference, the JSON str will get truncated if it is too long, but this only happens in the debugger window. The problem was actually being caused by linefeeds present inside the some of the fields (despite having rules in place to fix this in my script).

 

Thank you @deanishe and @Mr Pennyworth for your willingness to help.

 

Edited by Bernardo_V
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...