===== 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) {
  function escapeString(str) {
    return (
      '"' +
      str.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');
        }
      }) +
      '"'
    );
  }

  function serialize(val) {
    if (val === null) return 'null';

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

    if (typeof val === 'boolean') {
      return val ? 'true' : 'false';
    }

    if (typeof val === 'number') {
      return isFinite(val) ? String(val) : 'null';
    }

    if (typeof val === 'bigint') {
      throw new TypeError('Do not know how to serialize a BigInt');
    }

    if (typeof val === 'string') {
      return escapeString(val);
    }

    if (typeof val === 'object') {
      if (typeof val.toJSON === 'function') {
        return serialize(val.toJSON());
      }
      if (val instanceof Number || val instanceof String || val instanceof Boolean) {
        return serialize(val.valueOf());
      }
      if (Array.isArray(val)) {
        const elements = val.map((item) => {
          const res = serialize(item);
          return res === undefined ? 'null' : res;
        });
        return '[' + elements.join(',') + ']';
      }

      const entries = [];
      for (const key of Object.keys(val)) {
        const itemVal = val[key];
        const res = serialize(itemVal);
        if (res !== undefined) {
          entries.push(escapeString(key) + ':' + res);
        }
      }
      return '{' + entries.join(',') + '}';
    }

    return undefined;
  }

  return serialize(value);
}

module.exports = { jsonStringify };
```