1

//While Saving this JSON to mongodb

{
    "data":{
        "username" : "xxxx",
        "servername" : "yyy@gmail.com",
        "sender_email" : "zzz@gmail.com",
        "port_no" : "134",
        "password" : "hello123",
        "confirm_password": "hello123",
        "notifiction":{
            "recipient":{
                "run_reports":["xxx4@gmail.com",
                "yyyyn@gmail.com",
                "yyy@gmail.com"],

                "run_analysis":["xxxgmail.com",
                "yy@gmail.com", "yyy@gmail.com","xxx@gmail.com"]
            }

        }
    }
}

// In my database, its saves like

bodyObj { data: 
   { username: 'balajikr',
     servername: 'mail.balaji.com',
     sender_email: 'amsa@gmail.com',
     port_no: '1324',
     password: 'hello123',
     confirm_password: 'hello123',
     notification: { recipient: [Object] } } }

recipients are not saved in my db Help me how to do it Thanks in Advance

krbalaji
  • 454
  • 4
  • 12
  • JavaScript 101. `console.log()` does not "deep serialize" objects. Use `JSON.stringify`, [just like the existing answer says](https://stackoverflow.com/a/4293047/2313887) – Neil Lunn Nov 16 '17 at 12:45
  • Hello Mr.Neil Lunn. I already stringify my JSON Objects. I am not straightly forwarded my error to stackoverflow. I already searched & then nly ask the question. – krbalaji Nov 16 '17 at 13:34
  • I checked & use with console.log() there is nothing has to be affected. its work good. But I am not directly save in to my db. I send that JSON object to another project there only I saved. There is an error while using it – krbalaji Nov 16 '17 at 13:41
  • In your question *"In my database, its saves like"*. So I don't think you understand. By your statement the data is "saved". What I am telling you is when you `console.log(data)` and you see `recipient: [Object]`. you instead do `console.log(JSON.stringify(data, undefined, 2))` and you then actually see the full structure that is really there instead of `[Object]`. That's what we mean by "serialize", is "displaying it". No code in your question at all, but if it "saves" then it's there.\ – Neil Lunn Nov 16 '17 at 20:35
  • Yeah. Catch it. thank you @NeilLunn – krbalaji Nov 17 '17 at 05:35

0 Answers0