0

I have a JSON object what I want to be parsed with pug. For example, the object looks like this:

{
   "name": "testname",
   "type": "news",
   "meta": {
       "author" : "authorname",
       "time": "2017-08-23T06:37:43.505Z"
   },
   "content": "lorum ipsum...."
}

I can use the data with is directly in the object like name and type with the default code: #{news.name}. But the data in meta not. #{news.meta.author} is not working because

Cannot read property 'author' of undefined

How can I acces that data?

NVO
  • 2,566
  • 5
  • 27
  • 57
  • How are you sending the data to Pug? Is it inline? Are you sending through something like Express? – Quangdao Nguyen Aug 23 '17 at 13:30
  • @QuangdaoNguyen Not really, I'm using this code as an email template, which is used in a javascript function which compiles this template and send the compiled html as an email. The compile function is sending the error. – NVO Aug 23 '17 at 13:34
  • I think this question has been asked before and already has an answer https://stackoverflow.com/questions/9463233/how-to-access-nested-json-data – I_Al-thamary Aug 23 '17 at 13:34
  • Hmm, it looks like I cannot acces `#{news.meta}` at all. However when I do an `JSON.stringify(news)` I see the meta property. But the `JSON.stringify(news.meta)` is empty. The `findProp()` function from the linked question gives me too an empty line of data. – NVO Aug 23 '17 at 13:56

0 Answers0