Extracting a string out of JSON returned

I’m saving my auth tokens to local storage for persistence, but when I get it back, the item is returned as JSON and I have no idea how to stringify it or extract the string to store in appVar.auth which only accepts string. Moreso to get the currentUser, i need to authorize using the token to get back the owner of the token and it’s usually “bearer tokenkey” - a string.

Please someone familiar with this help out. Also new here, barely 36 hours in.


You could try using a formula In a ‘Set App Variable’ logic element.

There are functions that will help you such as STRING - and depending on whether you need to extract smaller chunks of the data, SUBSTRING… - you can also create strings by joining other strings together using +

The descriptions in the formula editor are pretty helpful.

I hope that helps.

Thanks @Oli_Clark. TBH, I have tried every formula in the functions. There is no function for extensively manipulating or transforming JSON in function libraries. I already tried STRING, UTILITY, OBJECT, ARRAY, pretty much everything there.

So to reproduce my experience, search for ‘Set item to storage’ and ‘Get item from storage’ in the Flow Function Market and install. Then set a random string to storage with any Key of your choice. Next use the same Key to get the item from storage. When it returns, it’s no longer a string but a JSON type. You are not able to add it to say appVars.randomString which stores only string. See what I mean. Now there are no tools that allow you much like you would use schema to extract the string you want in the Data tool.

Finally, if anyone can point me to how I might persist a user token in Appgyver without banging my head against the wall will be very much appreciated.


Not quite sure what is the problem here. If you have valid json in the storage you should be able to access any property with simple dot notation. e.g. appVar.auth.token or what ever its key is defined as.

if its stringified you can use ENCODE_JSON

Please elaborate if there’s something I’m missing here.

Hi @Sasu_Makinen, I am unable to ENCODE_JSON or apply dot notation.

Perhaps can you walk me through how you would store a token to a user’s browser and retrieve it back on page load into string appVars for use until user refreshes or closes app. I have struggled with this problem for the past 12 hours or so. If there is a better way, I’m pretty sure I’m way so off at this point.


I have logic like this which returns the token string as it should to my page variable.
The Get item from storage could be in app launched event logic just as well.

If there’s some odd specific bug going on you could give your app id and consent for us to check it out in your app, if you want to.

Thanks @Sasu_Makinen. Please find my addId below: I have a flow setup on the Global Canvas. Thanks

appId: “97647”

I trust we had a great weekend, anyone able to help look through my app?

Can’t really reproduce the issue as I don’t have any authentication methods for your app. I would try to see what happens right after you call login in your log in page. Try to use debugger to see if outputs are what you expect, or just do an alert box with ENCODE_JSON(outputs['my auth flow'].response and see if there’s something wrong, also get the storage item right after setting it and see if it’s there. Looking at the logic I can’t find any clear issues.

Hello @Sasu_Makinen. Apologies for the delays in responding.

Please use the user to authenticate

email: user+3@gmail.com
password: pass

I implemented the same logic you have in your login canvas and an API that gives an exact response as the auth API you’re using with an example value.

I have no issues in saving or requiring my token. Are you using Web/ios/android? which model or browser? Any plugins or extensions that could have an effect?

In the setup presented in the video everything works as expected.
Is there any errors presented to you when running? In browser console or mobile logs?

Thanks again @Sasu_Makinen

I finally found where the issue was. I had the Get Data too early in my flow and for some reason I just never caught it. I placed it after set appVars.auth and it fixed it like magic.

Thanks for your patience and support

1 Like

Hi @Sasu_Makinen thanks for all the help.

Unfortunately i need more help. How do I set up so that if a user has a valid auth token, they skip the login page and if a user doesn’t have one is routed to the login page. I have checked the docs but can’t find anything relating to this.


You set login page as the “initial page” in the navigation tab, and then at the login view, or global canvas, you check for the token in the storage and open a different page if its ok.

Thanks @Sasu_Makinen

1 Like

@Dika_Oha did you figure it out?

Yes @Harri_Sarsa and @Sasu_Makinen. I wish it never showed the login page before redirecting to the homepage if the user has a valid token. But works for now.

Hello @Harri_Sarsa, @Dika_Oha, @Sasu_Makinen,
I have a JSON response from a backend server (Google Cloud Firestore) which is embedded in a message as shown below.

JSON error response from server: {“error”:{“code”:400,“message”:“EMAIL_EXISTS”,“errors”:[{“message”:“EMAIL_EXISTS”,“domain”:“global”,“reason”:“invalid”}]}}.

Am now struggling to extract the JSON objects in the above error message.

  1. I tried using RIGHT_STRIP(LEFT_STRIP(outputs[“Create record”].error.message, 33),1) with a

Formula to strip it down to the below.


which looks like a JSON formatted data but i couldn’t access any of the various items using the keys.

not sure if the above extracted JSON message is being seen by Composer as a String rather than a JSON object.

  1. I also tried saving the extracted JSON information using the “Set Item To Storage” and later
    retrieved it using the “Get Item From Storage”. I tried it this way because the “Get Item From Storage” does return a JSON formatted data. But still, i couldn’t extract any of the values from the extracted information.

Any help would be very much appreciated. Thanks

Hi @lyn_Wayne This {“error”:{“code”:400,“message”:“EMAIL_EXISTS”,“errors”:[{“message”:“EMAIL_EXISTS”,“domain”:“global”,“reason”:“invalid”}]}} is a JSON object in and of itself. You don’t need to extract it if you want to use it as is.

The formulas you used are for string types and not JSON or Object. If you can elaborate on what you want to do with the error response, perhaps we might be able to guide better on approach to take.

A simple thing you can do to figure this sort of thing out is to create a Page Variable matching the exact schema of the error response. This way you can access a property/key using formulas or via pageVar binding to a view component. Playing around with setting stuff from a backend resource to a variable has help me to understand the inner workings of Appgyver faster.

Hello @Dika_Oha,
Please see the message received from the backend server. It’s a string of messages with the JSON information embeded within. What i meant earlier was, i used formulas to extract the JSON component from the received response.

As explained earlier, i wanted to extract the error messages from the JSON response. for example: