# MongoServerError: Change stream pipeline must be a valid JSON array: invalid JSON input at position 10

- **ID:** `mongodb/change-stream-invalid-json`
- **Domain:** mongodb
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

The change stream pipeline argument was passed as an invalid JSON string or malformed array, often due to string concatenation errors in application code.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| MongoDB 5.0 | active | — | — |
| MongoDB 6.0 | active | — | — |
| MongoDB 7.0 | active | — | — |

## Workarounds

1. **Ensure the pipeline is passed as a native array object, not a JSON string. In Node.js: db.collection.watch([{$match: {operationType: 'insert'}}]). In Python: db.collection.watch([{'$match': {'operationType': 'insert'}}]).** (95% success)
   ```
   Ensure the pipeline is passed as a native array object, not a JSON string. In Node.js: db.collection.watch([{$match: {operationType: 'insert'}}]). In Python: db.collection.watch([{'$match': {'operationType': 'insert'}}]).
   ```
2. **Validate the pipeline JSON using JSON.parse() in JavaScript or json.loads() in Python before passing it to the watch method.** (90% success)
   ```
   Validate the pipeline JSON using JSON.parse() in JavaScript or json.loads() in Python before passing it to the watch method.
   ```

## Dead Ends

- **** — Adding extra quotes around the pipeline array does not fix the JSON parsing; it causes additional syntax errors. (90% fail)
- **** — Using a string instead of an array for the pipeline (e.g., '[{"$match": {}}]') is parsed as a string literal, not an array. (95% fail)
