JSON fields are not returned as an object (when stored as a string)
- Vorherrschende Sprache
- JavaScript
- Sterne
- 2k
- Forks
- 238
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
At the moment i need to use for every JSON field this code before storing an item:
``` javascript
User.validate('settings', function(err) {
if (typeof this.settings !== 'object') {
try {
this.settings= JSON.parse(this.settings);
} catch (e) {
err();
}
}
}, {
message: 'Invalid JSON'
});
```
Would be nice if there would exist a function that does that automatically and throws an error when the field can't be converted to an object.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Look at the schema definitions for JSON fields in jugglingdb's adapters (like mysql, postgresql). The issue is about automatic JSON parsing when a string is stored. Start by finding where field types are defined and how data is serialized/deserialized. Check existing validation or coercion logic. The goal is to add a function that automatically parses JSON strings to objects and throws on invalid JSON, eliminating the need for manual validation.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, mongodb, mysql, nodejs, postgresql, redis, sqlite
- Bereich
- backend, database
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100