Json error when parsing json file

Options
I've got simple json file
{
"squadName": "Super hero squad",
"homeTown": "Metro City",
"formed": 2016,
"secretBase": "Super tower",
"active": true
}When I try to import it using External API Request I've got exception:
Exception: Unable to locate var: json.response.result.homeTown
My steps:
1.  https://groster.me/webhook/heros1.json
: return as json
2. Create Variable
: var:json.response.result.homeTown as var_1


http://joxi.ru/v29jxWIZMPZyAG - screenshot of error

I suppose it is a bug, right? If not, how to correct the code?

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    Hey  - my first though is that the path is incorrect. Are you able to use the SUBPATH method to traverse through your data? First run your external API - once you see the results copy the results as JSON. Create a new variable, hover over the var from the api response and select subpath, then paste the response in and select define. Then you can click on the exact level you want to return and it should automatically create the right path.

    The other question I have is does homeTown ever come back as empty or it's not included? or is your API static or it has data everytime?
  • Pavel
    Pavel Member
    Options
    Hi Michael.
    I had two errors Exception: Unable to locate var and Exception: Unable to decode. I was making the same steps that you described but couldn't get right result. At last I decided to decode json file to UTF-8 and it worked!

    Please make a note somewhere about the encoding json files for import
  • Glenn McWhinney
    Options
     Hey Michael. I've had this exact issue with a result from an external API request and although I can see the correct 200 response, and I can traverse the data structure, I get this error: [image.png]I used the response from the data provider (maxmind) to define the JSON and the subpath as you describe above. What am I doing wrong please?[image.png]
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
     - your response probably isn't always returning the expected path. For this, you can use the GET filter in lieu of dot notation so that you can define a default value so your function stack continues to run.

    https://docs.xano.com/working-with-data/dot-notation#get-filter
  • Glenn McWhinney
    Options
     Thanks for this but... when I run & test and inspect the result in the debugger, I can see the expected path is there + the value I expect (GB). I'll certainly have a look at the get-filter approach too but not sure it solves this situation I'm in? Happy to jump on a quick support call if it helps?
  • Glenn McWhinney
    Options
     I've implemented the GET filter as you say, but now it always returns the Default value (I'm assigning: NA) but at least it is not falling over - small blessings! Has the depth of the path got anything to do this not finding the var? i.e. there's a further node to traverse before you get to the "iso_code" as you see here:[image.png]All help most appreciated 🙏
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
     if it's always returning the default value then your path is likely incorrect.

    I've been assuming var: country_code_json has a path associated with your original response but perhaps not. When in doubt, you can use SUBPATH to ensure you are getting the correct path and spelling (note: the GET filter is still handy to use if the data structure coming back can vary, so I'd recommend it for its flexibility). 
  • Glenn McWhinney
    Options
     Thanks Michael. Sorted it. The path was even more nested than I had realised!

    json > response > result > country > iso_code

    I was skipping the "response" part but having broken it down, and using GET filters, I can see the value I want:[image.png]I can probably avoid setting all those variables now and use a single subpath but for this instance, I'm going to keep this in. Thanks for your help.