typicode / json-server

Get a full fake REST API with zero coding in less than 30 seconds (seriously)
Other
72.67k stars 7.01k forks source link

Support an option to control the JSON format #1302

Open jellehak opened 2 years ago

jellehak commented 2 years ago

Currently the JSONFile adapter of lowdb uses JSON.stringify(obj, null, 2) which works nicely in most situations. However most 'production' situations would strip away the whitespace for performance. Therefor to have a better 'mock' server it would be nice to control the stringification process of the JSON ( both saving as reading ). Related file: https://github.com/typicode/lowdb/blob/main/src/adapters/JSONFile.ts

Pretty: JSON.stringify(obj, null, 2) Plain: JSON.stringify(obj)

Possible ideas

json-server --plain db.json
json-server --pretty db.json
ericnewton76 commented 2 years ago

Thumbs down from me on this. Considering json-server shouldnt ACTUALLY BE USED FOR PRODUCTION, this is a superfluous request...

Use a more performant and battle hardened JSON document storage like MongoDB or similar.

jellehak commented 2 years ago

@ericnewton76 sad to hear a thumbs down. The idea is to have a better mock that comes closer to what an actual response on a production server would look like which is probably not prettified.

Demianeen commented 1 year ago

Actually, there is an issue with formatting not only in production. I really like to use json-server for pet projects or for test assignments and I use prettier there. And every time I commit I see tons of changes in db.json because Prettier formats only on a commit with lint-staged, which is very annoying. Can I somehow disable formatting?