JSON fields are not returned as an object (when stored as a string)
- Lingua principale
- JavaScript
- Stelle
- 2k
- Fork
- 238
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, mongodb, mysql, nodejs, postgresql, redis, sqlite
- Ambito
- backend, database
- Tipo di issue
- Funzionalità
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100