===== ISTEM =====
Solve the following programming task.

TASK: Custom JSON.stringify

Write a function 'jsonStringify(value)' that converts objects, arrays, strings, numbers and booleans into JSON text without using the native JSON.stringify.

STARTER CODE (javascript):
function jsonStringify(value) {
  // Write your code here
}

module.exports = { jsonStringify };


RULES:
- Keep the function name and signature EXACTLY as given.
- Return working code only. No explanations.
- Put the code in a single ``` block.
- Try to solve it first. If you genuinely cannot, write only this single
  line instead of producing faulty code: CANNOT_SOLVE

===== HAM YANIT =====
```javascript
function jsonStringify(value) {
  if (value && typeof value.toJSON === 'function') {
    value = value.toJSON();
  }

  if (value === null) {
    return 'null';
  }

  const type = typeof value;

  if (type === 'undefined' || type === 'function' || type === 'symbol') {
    return undefined;
  }

  if (type === 'boolean') {
    return value ? 'true' : 'false';
  }

  if (type === 'number') {
    return Number.isFinite(value) ? String(value) : 'null';
  }

  if (type === 'string') {
    return (
      '"' +
      value.replace(/[\\"\u0000-\u001f]/g, (c) => {
        switch (c) {
          case '"':
            return '\\"';
          case '\\':
            return '\\\\';
          case '\b':
            return '\\b';
          case '\f':
            return '\\f';
          case '\n':
            return '\\n';
          case '\r':
            return '\\r';
          case '\t':
            return '\\t';
          default:
            return '\\u' + c.charCodeAt(0).toString(16).padStart(4, '0');
        }
      }) +
      '"'
    );
  }

  if (Array.isArray(value)) {
    const elements = value.map((item) => {
      if (
        item === undefined ||
        typeof item === 'function' ||
        typeof item === 'symbol'
      ) {
        return 'null';
      }
      const res = jsonStringify(item);
      return res === undefined ? 'null' : res;
    });
    return '[' + elements.join(',') + ']';
  }

  if (type === 'object') {
    const keys = Object.keys(value);
    const pairs = [];
    for (const key of keys) {
      const val = value[key];
      if (
        val === undefined ||
        typeof val === 'function' ||
        typeof val === 'symbol'
      ) {
        continue;
      }
      const res = jsonStringify(val);
      if (res !== undefined) {
        pairs.push(jsonStringify(key) + ':' + res);
      }
    }
    return '{' + pairs.join(',') + '}';
  }

  return undefined;
}

module.exports = { jsonStringify };
```