You can just use JSON.stringify(someData) to turn it into a string, and then btoa(yourString) to base64 encode it (and atob(yourBase64String) to decode it).
Keep in mind that there are limits to the max header length of the URL, so depending on the size of what you want to store it may simply not be possible to fit within the state param.
Usually you would do as Barry says and first use the State param to prevent CSRF attacks, and then on top of that add any small amount of state data such as the users location on your site. If you need to store lots of data it would be better to store that data on the server, which the user can retrieve when they load your page (even after coming back from the OAuth flow), or store the data within a cookie or localstorage.