Base64 encoding of an array of objects

Hello @Allys1098,

To maintain the structure of your data, you need to stringify your array before encoding and then parse it after decoding.

Encoding on the First Page

Convert your array to a JSON string before encoding it:

const dataArray = [
  { "id": 0, "name": "accessToParking" }, 
  { "id": 1, "name": "accessToShow" }
];
const jsonString = JSON.stringify(dataArray);  // Converts array to a JSON string
const encodedData = btoa(jsonString);          // Encodes the JSON string to base64

You can now safely pass encodedData as a URL parameter.

Decoding on the Second Page

When retrieving the parameter, decode and parse it back into an array of objects:

const encodedData = getParameterByName('yourParamName');  // Extracts the parameter from the URL
const jsonString = atob(encodedData);                     // Decodes the base64 string to JSON
const dataArray = JSON.parse(jsonString);                 // Parses the JSON string back to an array of objects
4 Likes