Exchanging Files with Server
7/15/2019 1:09:32 PMStan Berger
14 AnswersNew Answer
Lisa F you could use mysql npm package with node, to retrieve mysql data and convert it into JSON. Here is the sample code, you can use. https://glitch.com/edit/#!/mysql-to-json The result of the console log would display the json string (Select "Tools" followed by "Logs")
Lisa F Ah... I thought you thought his data was stored in MySQL and wanted to know how he converted it to JSON. 🤦♂️ Instead... you were just generally asking about how to convert data stored in MySQL into JSON that gets sent to the browser. 😉 In that case, there are many ways to manage this with all sorts of pros and cons. The conventional approach is to load the data into an object model on the server. There are a number of ways this can be done as well... each with advantages and disadvantages. The specific method will depend on the language, platform, frameworks in use, etc. Let's assume you are using some ORM, which is a library for loading data from a database into some object model you can interact with in code. This object model could then be used directly or it could be used to create another object matching the expected JSON structure. Either way, a JSON library or builtin functions (depending on the language and platform) will be used to serialize the object into a JSON string.
Stan Berger you could use json server to build rest api. And use Axios to fetch the api from frontend and populate the data on a table. Here a sample code built from json server and Sololearn code as frontend web access. https://glitch.com/~slloves https://code.sololearn.com/W3Qe5hqksyLe/?ref=app
Stan Berger json server accepts post request too. Check out this code https://code.sololearn.com/Wj7yW7R4iSId/?ref=app
So, instead using PHP and mySql to update the data, We should use Js and JSON which only can store the data and create the table but can't update the database. This question post also asking about how to upload or update the database
Adi Pratama-Universitas Brawijaya json_server allows us to read/write the server json file, please check out my code i shared previously.
ty David Carroll and yes your answer really helps. concepts are the hardest questions to ask about but until you wrap your head around the big picture the details don't really make sense. ty I personally can't imagine life without needing to involve a relational database somewhere in the application but am starting to appreciate nosql databases too ....so just starting to figure out how that all mixes together in one app. so here's another basic question...what are the key characteristics of data that tells you that it doesn't need to be stored in a relational database?? again ty!!
Lisa F I don't believe he's using a relational database. Based on his previous comments, he's working against a JSON file on the server.
David Carroll is right, the previous code was based on a json file, json server compiles the json file into internal db as init data whenever it changes.
I think this is a great question but it covers sooo many areas folks maybe decided not to answer. break it down and you'll get responses. what exactly do you want to do? exchange files? or build a data driven app where users can both select and update data in a database???
Thank you both, Lisa and Calvin! Yes, I would like to learn how build my own data driven app where users can both select and update data in a database. Calvin, I like your solution for creating a table using JSON objects.
Calviղ ty for sharing your knowledge so freely! if some of your data is stored in a relational database such as mysql how do you recommend getting it into a json format? i guess I don't know where SQL fits into this. tytyty
Lisa F I love this follow up question. So we don't completely hijack this question, post this as a new question and tag me there. I'll respond when I get a free moment. 😉
David Carroll understand....was adding a new wrinkle to the question