Filtering JSON object using Google Apps Script

Gists

This is a simple sample script for filtering JSON objects using Google Apps Script.

In the current stage, V8 runtime can be used with Google Apps Script. By this, when you want to filter a JSON object, you can use the following sample script.

Sample script

In this sample script, obj is filtered by the value of the even number.

const obj = { key1: 1, key2: 2, key3: 3, key4: 4, key5: 5 };
const res = Object.fromEntries(
  Object.entries(obj).filter(([, v]) => v % 2 == 0)
);
console.log(res); // {"key2":2,"key4":4}

References

 Share!