Reputation: 1
I have been asked by a employer to download and import JSON file to your firebase database. I have used firebase in Android project. But in this case iI have applied for web development internship and I am not aware how to do the same for that is to have database i need to link an app for that. The employer has provided me with a script file and a JSON file. Am I expected to use a new app of my own?
Upvotes: 0
Views: 3416
Reputation: 7411
I assume that your script file will have details about the firebase project(API keys). You can import it as per documentation.
After that, you can import your JSON, something like this:
var database = firebase.database();
database.ref('path/where/you/want/to/import').set(yourjson);
To read json from your file, this answer may help you with that: https://stackoverflow.com/a/24378510/1820644
To initially try, I recommend trying this on an new firebase project. After you got this working, try it out with the database you have been given. Create a new firebase project and try to do this thing on that project.
Hope it will help you.
UPDATE:
If you have a URL to your json file (and not the local json file), you might want to get it like this:
// using jquery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$.getJSON( "ajax/test.json", function( data ) {
var database = firebase.database();
database.ref('path/where/you/want/to/import').set(data);
});
});
</script>
Upvotes: 1