Correct way of importing data from json in Ionic 2 using an interface - json

I'm really wondering what's the correct and best-practice way for importing data from a json file in an ionic 2 project so I can show it in a template, for example.
Some solutions I can find use interfaces, some don't. Some implement own small services, some don't. Some use http.get().map().subscribe(), some just use subscribe(). I would really like to know how to do this properly and would be glad if somebody could enlighten me.

From my view the best practice is to use a service and use http get request to get json file from your server. We did the same for getting language json file.
If you want securely get json file then you should put your json file at secure folder rather than public folder and create an api to get json file or json object from server.
Hope it will help

Related

How to save data with JSON in a Xamarin app?

Good day dear developers, I really need your help. I want to make an app in Xamarin. In which I added some text data, and it is saved in this application. I need this information to be in the application, and I could get it without the Internet. I understand that you need to use JSON. I really want you to at least give a little hint on how I can store information using JSON in my Xamarin application. Thanks a lot!)
I tried to find information on Google, but there is a lot of superfluous and inappropriate
Depending on your data an easy way could be to use Preferences from Xamarin.Essentials which allows you to store key/value pairs: link to description
Another option would be to save files with JSON as you mentioned already. You create a class which holds your data and then serialize/deserialze the objects to files and from files. For this you can use the Newtonsoft.Json which is a nuget package that you can install.
If you have a MyData class and an data object it would look like this:
Serialize:
File.WriteAllText("fileName", JsonConvert.SerializeObject(data));
Deserialze:
var myData = JsonConvert.DeserializeObject<MyData>(File.ReadAllText("fileName"));
Different platforms has their own file system. For example, iOS limits our access to the file system, which is called Application sandbox. To save or load files, you could learn some basic info first:
for iOS, refer to File system access in Xamarin.iOS.
for Android, refer to File Storage and Access with Xamarin.Android
Xamarin forms provides several ways to use Xamarin forms local data storage. First is use File Handling just as Mario K mentioned. For Serializing JSON, you could refer to Serializing JSON.
Another is that you could use SQLite database engine which allows Xamarin.Forms applications to load and save data objects in shared code. More info, you could refer to Xamarin.Forms Local Databases.
I think you could first check these documentation and decide which method you prefer to use. If you still have questions, feel free to ask.
Hope it works for you.

How to upload an image using node.js+mysql+express?

I am new to Node.js ,with the help of this
tutorial I've learned how to write REST API using Node.js .Can anybody please help me to understand how to upload an image file using Node.js and saving it in mysql table ? I've been searching for it , but couldn't get something useful . Any help would be useful to me.
Typically files are uploaded as multipart form data from a web page. You could start there with a simple <input type="file"> on a web page.
Create an endpoint in Express, and consider a package to help parse it. One like express-formidable would be a good start. Then you will have the file from the request.
To save to mysql, I'd suggest the package knexjs. This is a nice library to programmatically write SQL queries. You'll have to define your own tables that store the image (probably as BLOBs) and you can use Knex to store the new images into your DB.
Be aware of the asynchronous flow in NodeJS. For your Express endpoints, you only want to finish the response after the DB code is done, like inside the knex call's callback (or at the final .then() of a promise chain)

Polymer:how to handle csv file upload and convert to json and send to server

i want to handle a requirement in polymer webcomponents where user can upload csv file from ui and csv file can be parsed to json and sent to server ,i searched and found for vaadin upload,looked over the api but i am not sure how to receive the csv file and convert to json and sent to server,can anyone show a jsfiddle of vaadin upload or any other web component to handle this scenario?
First of all, I am wondering why you would not simply do the conversion on the server side.
In this case, you would be able to use the vaadin-upload directly indeed.
Here is a snippet that would upload all files to the example.com server, and only allow CSV files.
<vaadin-upload target="https://example.com/upload" method="POST" accept="text/csv">
</vaadin-upload>
There are plenty of resources on how to convert CSV files to JSON.
Here is a snippet
And here is a node library
If you really wanted to do the conversion client side, then I would suggest to create an element that would embed a vaadin-upload, and convert the Files array to Json before manually calling the uploadFiles method.

Angular2 updating JSON file

I have hosted a JSON file on my server locally. I am working with angular2 right now and have a JSON object that is to be used to overwrite the original one in the JSON file hosted. How do I do that? I am really new to these concepts.
cannot understand scenario clearly that what you want to achieve ?
cause if you want to change something on server meaning(JSON file)
then you need server side scripting ie. NodeJS,PHP,Java and angular 2 is only for client side so basically angular 2 has no access to change anything from server. Hope it helps or help me to clear scenario you are fighting.

Save Json to online database GAE or Firebase

I am new to JSON and online databases. I have learned the basics of using .js files and manipulation on them. But I have no clue how to save them onto GAE or Firebase databases.
1)My question is, are every online databases uses JSON differently when they store them?
I have no idea what it looks like storing onto an online database so
2)Can you give me an example of JSON stored in Firebase or GAE. Links to tutorials are also helpful.
Firebase is a true "online database" in a sense that you can save/retrieve/query data to it, without actually writing any code on the server. As such, it is close to Backend as a Service offerings, such as Parse, Kinvey, etc.. Search the web to find more services and compare features that you need.
OTOH, GAE is an application platform - you will need to write server-side code to create any functionality.
As for examples: please RTFM.
GAE's ndb datastore API has a JsonProperty:
https://cloud.google.com/appengine/docs/python/ndb/properties
It's easy to store a JSON object as a StringProperty, using json.loads, json.dumps to parse. For a simple list, you can use a StringProperty, and giving it the repeated=True tag:
https://cloud.google.com/appengine/docs/python/ndb/properties#repeated