Skip to content

isJSON(something)

The isJSON(something) function is a custom JavaScript utility available within the MerciGlobal Cloud ERP codebase. It is designed to validate whether the provided input is a valid JSON string.

Purpose

To check if a string can be parsed as valid JSON.

Returns

  • true — if the input is a valid JSON string.
  • false — if it is not a valid JSON string.

Usage

isJSON('{"key": "value"}');      // true
isJSON('[1, 2, 3]');               // true
isJSON('Invalid JSON');           // false
isJSON(12345);                    // false

Internal Implementation

This is a simplified internal MerciGlobal implementation:

function isJSON(input) {
  if (typeof input !== 'string') return false;
  try {
    const result = JSON.parse(input);
    return typeof result === 'object' && result !== null;
  } catch (err) {
    return false;
  }
}

Use Cases in MerciGlobal Cloud ERP

  • ✅ Validating user-imported data.
  • ✅ Pre-checks before parsing API payloads.
  • ✅ Error-proofing configuration files or runtime settings.

Notes

  • This function is lightweight and doesn't add external dependencies.
  • It should be used before any JSON.parse() call to avoid runtime errors.

For more such utility functions, refer to the MerciGlobal Cloud ERP Utilities Library.