@Fox Ok nevermind thanks for the help. I didnt see that link when I searched that link you sent me. But all I had to do was remove the quotation marks in my own script and it worked.
For those who needs this later, you can set up http proxy and send a simple get request to https://api.ipify.org , it will give you the ip adress in plain text, no need to parse the json.
One of many simple and easy ways to do it.