Jump to content

Script Filter - JSON error: JSON text did not start


Recommended Posts

Working on Workflow...Script Filter Alfredv3.1.1 (737) Mac O SX 10.12

 

Dropbox Link

<removed>

 

Trying to get the results displayed as choices in Alfred.

 

Error

[ERROR: input.scriptfilter] JSON error: JSON text did not start with array or object and option to allow fragments not set. in JSON

 

With (bash)
base_uri="https://xyz.execute-api.us-west-2.amazonaws.com/prod/listfromalfred?user=${user}&task=${data}"

post_result=$(/usr/local/bin/curl  -X GET ${base_uri})

post_success=`echo ${post_result} | grep items` 

echo ${post_success} | sed 's/\\//g' 

 

This test code works
#test='<items><item uid= "test " arg= "one "><title>em11@mail.com</title><subtitle>em11@mail.com</subtitle><icon>icon.png</icon></item></items>'

#echo ${test} 

 

However, when I call the API I get:

'Response code: 200\n'

[2016-10-23 12:19:23][ERROR: input.scriptfilter] JSON error: JSON text did not start with array or object and option to allow fragments not set. in JSON:

"<items><item uid= "test" arg= "one"><title>em11@mail.com</title><subtitle>em11@mail.com</subtitle><icon>icon.png</icon></item></items>"

 

Debugging for hours and can't seem to fix the issue. Trying to get the results displayed as choices in Alfred. HELP ;)

Edited by JordanX
Added Dropbox Link
Link to comment

First of all, when you're having a problem, please post the broken workflow somewhere instead of pasting bits of it into the forum. Unless you're doing something very obviously wrong, it's almost impossible to diagnose an issue without being able to run the workflow. And expecting people to rebuild the workflow for themselves to help you debug is unreasonable.

 

That said, the "obvious" error here is that your XML is invalid. There's no closing </items> element in the XML from your API.

 

Presumably, Alfred can't parse the XML because it's invalid, so it's trying to parse it as JSON instead.

Link to comment

@deanishe

 

Yes, caught that and updated post. Still getting the same error. Happy to post the Workflow, any suggestions on how/where I should post it? 

 

[2016-10-23 12:19:23][ERROR: input.scriptfilter] JSON error: JSON text did not start with array or object and option to allow fragments not set. in JSON:

"<items><item uid= "test" arg= "one"><title>em11@mail.com</title><subtitle>em11@mail.com</subtitle><icon>icon.png</icon></item></items>"

 

 

Link to comment

You're not cleaning the server response properly. The server sends back this:

"<items><item uid= \"test\" arg= \"one\"><title>em11@mail.com</title><subtitle>em11@mail.com</subtitle><icon>icon.png</icon></item></items>"

But you only remove the backslashes:

"<items><item uid= "test" arg= "one"><title>em11@mail.com</title><subtitle>em11@mail.com</subtitle><icon>icon.png</icon></item></items>"

You still need to strip the surrounding double quotes and remove the spaces after uid= and arg=:

<items><item uid="test" arg="one"><title>em11@mail.com</title><subtitle>em11@mail.com</subtitle><icon>icon.png</icon></item></items>

 

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...