Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual modification of JSON file is a problem. #1486

Closed
githubpeti85 opened this issue Jan 13, 2024 · 4 comments
Closed

Manual modification of JSON file is a problem. #1486

githubpeti85 opened this issue Jan 13, 2024 · 4 comments

Comments

@githubpeti85
Copy link

How can I prevent the server from detecting it as an error if I manually enter it in the JSON file? If I write in the json data, I can no longer POST. I have to delete all the data from addresses where I didn't even post.
But I don't have to delete the first data address, it allows it to remain. I don't understand how it all works.
Thus, if something happens to the json file, we cannot replace the json file containing the backup because it will not work because it is not the same file.

@typicode
Copy link
Owner

Manually modifying the JSON file shouldn't result in a error. What would be the steps for me to reproduce the error?

@githubpeti85
Copy link
Author

Manually modifying the JSON file shouldn't result in a error. What would be the steps for me to reproduce the error?

There are only arrays in the json file.
{"object1":[["data1","data2","data3"], ["data11","data22","data33"], ],
"object2":[["data1","data2","data3"],["data11","data22","data33"], ],
"object3":[["data1","data2","data3"],["data11","data22","data33"], ]
}
If I change even one letter of the data in any array, it is not possible to send POST requests. GET request is not blocked.That means adding new data to the json file is no longer possible. And writes something like this to the console:

POST /cust6 500 26.369 ms - 965
TypeError: Cannot read properties of undefined (reading 'id')
Error reading A:\prog\databaselesolvd\db1.json
No data, empty input at 1:1
^
Read error has been fixed :)
GET /customers 304 22.338 ms - -

But you can't send POST requests even after that.

It only improves if I delete all the data and leave only the empty blocks.
object1":[ ],
"object2":[ ],
"object3":[]

This also happens if I modify the json file offline. And even if the modification does not include data modification. I do it in VS Code.

@githubpeti85
Copy link
Author

githubpeti85 commented Jan 14, 2024

In fact. I noticed that even if I restart the server, it does not allow me to POST to arrays that already contain data. You can only post in empty blocks until I stop snooping on the server. But if I restart it, it is no longer possible to post data in these blocks either. Is the problem that I run the controller with the -- watch db.json command?

@typicode
Copy link
Owner

Format should be an array of objects (just like the posts example). Array of arrays is unsupported actually (I'll document it)

{"object1":[  { "id": "1", "value": [ "data1","data2","data3"] }, ... ]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants