0

I have been working with a nested JSON file as given below. I want to write this JSON to a firestore document using node.js.

{
"title":"Sample tittle",
"icon":{
    "type":"url/base64",
    "url":"http://www.sample.com/icon.png"
},
"steps":{
    "step1":{
        "type":"play",
        "url":"http://www.sample.com/"},
    "step2":{
        "type":"ask",
        "url":"http://www.sample.com/ab14",
        "Opts":["yes", "no"],
        "next":[
            {
                "id":"step1",
                "answer":"yes"
            },
            {
                "id":"step3",
                "answer":"no"
            }
        ]
    },
    "step3":{
       "type":"play",
        "url":"http://www.sample.com/ase"}
}

}

3
  • Please show us what you have tried so far, or a specific issue you are having. Commented Nov 16, 2019 at 9:35
  • My main concern is will firestore let me add JSON which contains arrays? Commented Nov 16, 2019 at 9:48
  • 1
    Isn't your main concern solved once you try it? Commented Nov 16, 2019 at 10:30

1 Answer 1

1

There shouldn't be any problem with it. You can find nice reference on GitHub

https://github.com/googleapis/nodejs-firestore/blob/master/README.md

I have used it and was able to create document from your JSON like this:

const {Firestore} = require('@google-cloud/firestore');

// Create a new client
const firestore = new Firestore();

async function quickstart() {
  // Obtain a document reference.
  const document = firestore.doc('test_collection/test_document');


// Enter new data into the document.
  await document.set({
     <your JSON here>
  });
}
quickstart();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.