Here are some versions of @treznik's solution from Lodashy ES6
export function isSerialisable(obj) { const nestedSerialisable = ob => (_.isPlainObject(ob) || _.isArray(ob)) && _.every(ob, isSerialisable); return _.overSome([ _.isUndefined, _.isNull, _.isBoolean, _.isNumber, _.isString, nestedSerialisable ])(obj) }
Test
describe.only('isSerialisable', () => { it('string', () => { chk(isSerialisable('HI')); }); it('number', () => { chk(isSerialisable(23454)) }); it('null', () => { chk(isSerialisable(null)) }); it('undefined', () => { chk(isSerialisable(undefined)) }); it('plain obj', () => { chk(isSerialisable({p: 1, p2: 'hi'})) }); it('plain obj with func', () => { chkFalse(isSerialisable({p: 1, p2: () => {}})) }); it('nested obj with func', () => { chkFalse(isSerialisable({p: 1, p2: 'hi', n: { nn: { nnn: 1, nnm: () => {}}}})) }); it('array', () => { chk(isSerialisable([1, 2, 3, 5])) }); it('array with func', () => { chkFalse(isSerialisable([1, 2, 3, () => false])) }); it('array with nested obj', () => { chk(isSerialisable([1, 2, 3, { nn: { nnn: 1, nnm: 'Hi'}}])) }); it('array with newsted obj with func', () => { chkFalse(isSerialisable([1, 2, 3, { nn: { nnn: 1, nnm: () => {}}}])) }); }); _.isBoolean, _.isNumber, _.isString, nestedSerialisable ])(obj) }