MCPcopy Create free account
hub / github.com/Automattic/mongoose / toJSON

Method toJSON

lib/types/map.js:245–256  ·  view source on GitHub ↗

* Converts this map to a native JavaScript Map for `JSON.stringify()`. Set * the `flattenMaps` option to convert this map to a POJO instead. * * #### Example: * * doc.myMap.toJSON() instanceof Map; // true * doc.myMap.toJSON({ flattenMaps: true }) instanceof Map; // false

(options)

Source from the content-addressed store, hash-verified

243 */
244
245 toJSON(options) {
246 if (typeof (options && options.flattenMaps) === 'boolean' ? options.flattenMaps : true) {
247 const ret = {};
248 const keys = this.keys();
249 for (const key of keys) {
250 ret[key] = clone(this.get(key), options);
251 }
252 return ret;
253 }
254
255 return new Map(this);
256 }
257
258 inspect() {
259 return new Map(this);

Callers

nothing calls this directly

Calls 2

getMethod · 0.95
cloneFunction · 0.50

Tested by

no test coverage detected