Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return bad json including object(__proto__) from javascript(calling API)

I am calling api from javascript and that api is returning json. Calling json using following code :

document.ready(function(){
$.getJSON(url,
            function (data) {
               console.log(data);
               $("#test").text(data);
            });
        }
}); 

<p id="test"></p>

but it's showing only [Object] [object] to page. and in console.log, it's returning following json which is invalid including __proto__.

Object {author: "Hay House UK", title: "Top 15 Must-Read Books For 2014", text: "When a year ends, it’s like finishing a favorite b…elf-help slant conducive to healing planet Earth.", images: Array[2], date_created: "Wed, 01 Jan 2014 09:17:31 PST"…}
author: "Hay House UK"
categories: Object
business_finance: 0.039999999999999994
disaster_accident: 0.011428571428571427
education: 0.13887284818770693
entertainment_culture: 0.09647619047619045
environment: 0.08025982988254671
health_medical_pharma: 0.09809523809523808
hospitality_recreation: 0.04541137315797972
humaninterest: 0.04666666666666667
labor: 0.048559733653411985
law_crime: 0.01257142857142857
other: 0
politics: 0.12309533849221464
religion_belief: 0.03994037416667575
socialissues: 0.07857142857142856
sports: 0.05831770720339089
technology_internet: 0.014511842376414444
war_conflict: 0.053333333333333316
weather: 0.013888095736801704
__proto__: Object
cid: 1235024564
date: "Wed, 1 Jan 2014 08:00:00 GMT"
date_created: "Wed, 01 Jan 2014 09:17:31 PST"
html: "<div><div class="image_frame"><img alt="Hay House" src="http://www.healyourlife.com/img/resize_cache/1067-hay_house_logo_keep_aspect_215x215.jpg"></img><div class="caption">Hay House</div></div><div class="image_frame"><img alt="top books for 2014 hay house" height="215" src="http://www.healyourlife.com/img/resize_cache/3667-Top_15_Must_Read_Books_For_2014_keep_aspect_374x215.jpg" width="374"></img><div class="caption">top books for 2014 hay house</div></div><p>When a year ends, it&rsquo;s like finishing a favorite book. You really don&rsquo;t want it to end because you&rsquo;re still savoring all the good parts, but you also want to wrap it up so you can start the next one.</p><p>&nbsp;Before we close this chapter on 2013, we&rsquo;d like to share some of our most memorable Hay House books&mdash;our staff favorites&mdash;that this magnificent year has brought us. If you didn&rsquo;t get a chance to read any or all of these, we invite you to add them to your must-reads for 2014.</p><strong>&nbsp;</strong><strong>Top 15 Must-Reads to Start Your New Year</strong><p>1.&nbsp;<em>E-Squared</em>(Pam Grout): If you still don&rsquo;t believe that you have the power to shape the life you want, try any of the nine easy experiments in this book to prove that there really is a positive, loving, totally hip force in the Universe that&rsquo;s listening to your every word and that&rsquo;s ready to rock your world.</p><p>2. <a href="http://www.hayhouse.com/details.php?id=8149" target="_blank">Mind Over Medicine</a> (Lissa Rankin, M.D.): Have you always believed that the fate of your health is in the hands of your doctor, your genetics or sheer luck? Discover your body&rsquo;s innate ability to self-repair from the insights of a medical doctor.</p><p>3. <a href="http://www.hayhouse.com/details.php?id=8902" target="_blank">Assertiveness for Earth Angels</a> (Doreen Virtue): Do people take advantage of your niceness? Here&rsquo;s a great read for all those extremely sweet people who care more about others&rsquo; happiness than their own. Learn how set boundaries, find inner peace and be loving instead of &ldquo;too nice.&rdquo;</p><p>4. <a href="http://www.hayhouse.com/details.php?id=7626" target="_blank">All Is Well</a>(Louise Hay and Mona Lisa Schulz, M.D., Ph.D.): Like many of us, Dr. Mona Lisa read Louise Hay&rsquo;s little blue book and it changed her life. But she went one step further and collected scientific evidence to support what Louise has been teaching for years: that we each have the power to heal our bodies and our lives.</p><p>5. <a href="http://www.hayhouse.com/details.php?id=8170" target="_blank">Do Not Go Quietly</a> (George and Sedena Cappanelli): There&rsquo;s a demographic revolution&mdash;half of our population are 50 years of age or older for the first time in history. This book will guide all of us&mdash;GenXers (ages 30-45), Baby Boomers (ages 46-64) and Elders (age 65+) to work together to meet the challenges and opportunities in the days ahead. And for our future leaders&mdash;GenYers (everyone else!), there are tips for you, too!</p><p>6. <a href="http://www.hayhouse.com/details.php?id=8326" target="_blank">Love Your Enemies</a> (Sharon Salzberg and Robert Thurman): Two great minds join together to create this inspiring book on how to move past your pain, learn how to identify the people who challenge you (even yourself!) and learn to transform your relationships with them.</p><p>7.&nbsp;<a href="http://www.hayhouse.com/details.php?id=9229" target="_blank">Forgiveness</a>(Iyanla Vanzant): Iyanla says that forgiveness will cure anything that ails you, and she has created a powerful program to help you to forgive everyone for everything in just 21 days. Forgiveness will sharpen and broaden your vision. Are you ready to open your eyes?</p><p>8. <a href="http://www.hayhouse.com/details.php?id=7543" target="_blank">Archetypes </a>(Caroline Myss): Ever wondered why you are drawn to some people while turned off by others? Are you constantly searching for something, but you&rsquo;re not sure what it is? You&rsquo;ll find all the answers in your archetypes&mdash;the universal patterns that explain why we behave the way we do. Are you a Rebel, Artist, Visionary, Healer, Saboteur, Storyteller, Victim, Warrior? This book reveals all!</p><p>9. <a href="http://www.hayhouse.com/details.php?id=7935" target="_blank">The Honeymoon Effect</a> (Bruce Lipton): Think back on the most spectacular love affair of your life&mdash;the Big One that toppled you head over heels. Now you can understand and actually manifest this state of heartfelt bliss, robust health and abundance energy anytime you need it.</p><p>10. <a href="http://www.hayhouse.com/details.php?id=7637" target="_blank">The Tapping Solution</a>(Nick Ortner): Here&rsquo;s the latest craze that everyone is giving a try to help relieve their stress, alleviate pain and lose weight. It&rsquo;s the practice of tapping or Emotional Freedom Techniques (EFT). When you learn the amazing power of this technique, you&rsquo;ll be able to tap away your challenges and live a happier life.</p><p>11. <a href="http://www.hayhouse.com/details.php?id=9181" target="_blank">Second Firsts </a>(Christina Rasmussen): Have you lost someone you love? Through the author&rsquo;s personal experience of grieving the early death of her husband, you&rsquo;ll learn how loss can actually be a powerful catalyst to creating a life that is in alignment with your true passions and values.</p><p>12. <em>Nurturing Healing Love</em>(Scarlett Lewis): This book was inspired by the three words (Norturing Helin Love) that the author&rsquo;s six-year-old son Jesse wrote on their kitchen chalkboard shortly before he died during the Sandy Hook Elementary School shooting. Jesse&rsquo;s poignant words will teach you one of the greatest lessons in life: Love never ends.</p><p>13. <a href="http://www.hayhouse.com/details.php?id=9230" target="_blank">Power Words </a>(Sharon Anne Klingler): Words have undeniable power and incredible energy. They can make someone smile, sever a friendship, forgive a hurt and change the world. Find out which words will lift and empower you in every experience and encounter.</p><p>14. <em>The Dalai Lama&rsquo;s Cat and The Art of Purring </em>(David Michie): Here&rsquo;s the second delightful novel on the further adventures of His Holiness&rsquo;s Cat. Now this mischievous feline is searching for the true meaning of happiness&mdash;beyond the kind that comes and goes like a can of flaked tuna. This book&rsquo;s inspiring lessons will surely make you purr!</p><p>15. <a href="http://www.hayhouse.com/details.php?id=8174" target="_blank">The Last Laugh</a> (Arjuna Ardagh): If you love fiction with a twist of self-empowering wit and wisdom, enjoy this beautifully written and charming story about a young man who meets a quirky guru who finds a way to crawl into this troubled man&rsquo;s hardened heart and awakens his spirit. Lots of laughs and life lessons, too!</p><p>Hay House was founded in 1984 by Louise L. Hay as a way to self-publish her first two books, <i>Heal Your Body</i> and <i>You Can Heal Your Life</i> (YCHYL), both of which became bestsellers and established Louise as a leader in the New Age movement.  To date, YCHYL has sold more than 16 million copies worldwide and has been published in 25 languages. Today, Hay House is committed to publishing products that have a positive self-help slant conducive to healing planet Earth.</p></div>"
images: Array[2]
0: Object
1: Object
length: 2
__proto__: Array[0]
supertags: Array[3]
0: Object
1: Object
2: Object
length: 3
__proto__: Array[0]
text: "When a year ends, it’s like finishing a favorite book. You really don’t want it to end because you’re still savoring all the good parts, but you also want to wrap it up so you can start the next one.?Before we close this chapter on 2013, we’d like to share some of our most memorable Hay House books—our staff favorites—that this magnificent year has brought us. If you didn’t get a chance to read any or all of these, we invite you to add them to your must-reads for 2014.?Top 15 Must-Reads to Start Your New Year?1. E-Squared (Pam Grout): If you still don’t believe that you have the power to shape the life you want, try any of the nine easy experiments in this book to prove that there really is a positive, loving, totally hip force in the Universe that’s listening to your every word and that’s ready to rock your world.?2. Mind Over Medicine (Lissa Rankin, M.D.): Have you always believed that the fate of your health is in the hands of your doctor, your genetics or sheer luck? Discover your body’s innate ability to self-repair from the insights of a medical doctor.?3. Assertiveness for Earth Angels (Doreen Virtue): Do people take advantage of your niceness? Here’s a great read for all those extremely sweet people who care more about others’ happiness than their own. Learn how set boundaries, find inner peace and be loving instead of “too nice.”?4. All Is Well (Louise Hay and Mona Lisa Schulz, M.D., Ph.D.): Like many of us, Dr. Mona Lisa read Louise Hay’s little blue book and it changed her life. But she went one step further and collected scientific evidence to support what Louise has been teaching for years: that we each have the power to heal our bodies and our lives.?5. Do Not Go Quietly (George and Sedena Cappanelli): There’s a demographic revolution—half of our population are 50 years of age or older for the first time in history. This book will guide all of us—GenXers (ages 30-45), Baby Boomers (ages 46-64) and Elders (age 65+) to work together to meet the challenges and opportunities in the days ahead. And for our future leaders—GenYers (everyone else!), there are tips for you, too!?6. Love Your Enemies (Sharon Salzberg and Robert Thurman): Two great minds join together to create this inspiring book on how to move past your pain, learn how to identify the people who challenge you (even yourself!) and learn to transform your relationships with them.?7. Forgiveness (Iyanla Vanzant): Iyanla says that forgiveness will cure anything that ails you, and she has created a powerful program to help you to forgive everyone for everything in just 21 days. Forgiveness will sharpen and broaden your vision. Are you ready to open your eyes??8. Archetypes (Caroline Myss): Ever wondered why you are drawn to some people while turned off by others? Are you constantly searching for something, but you’re not sure what it is? You’ll find all the answers in your archetypes—the universal patterns that explain why we behave the way we do. Are you a Rebel, Artist, Visionary, Healer, Saboteur, Storyteller, Victim, Warrior? This book reveals all!?9. The Honeymoon Effect (Bruce Lipton): Think back on the most spectacular love affair of your life—the Big One that toppled you head over heels. Now you can understand and actually manifest this state of heartfelt bliss, robust health and abundance energy anytime you need it.?10. The Tapping Solution (Nick Ortner): Here’s the latest craze that everyone is giving a try to help relieve their stress, alleviate pain and lose weight. It’s the practice of tapping or Emotional Freedom Techniques (EFT). When you learn the amazing power of this technique, you’ll be able to tap away your challenges and live a happier life.?11. Second Firsts (Christina Rasmussen): Have you lost someone you love? Through the author’s personal experience of grieving the early death of her husband, you’ll learn how loss can actually be a powerful catalyst to creating a life that is in alignment with your true passions and values.?12. Nurturing Healing Love (Scarlett Lewis): This book was inspired by the three words (Norturing Helin Love) that the author’s six-year-old son Jesse wrote on their kitchen chalkboard shortly before he died during the Sandy Hook Elementary School shooting. Jesse’s poignant words will teach you one of the greatest lessons in life: Love never ends.?13. Power Words (Sharon Anne Klingler): Words have undeniable power and incredible energy. They can make someone smile, sever a friendship, forgive a hurt and change the world. Find out which words will lift and empower you in every experience and encounter.?14. The Dalai Lama’s Cat and The Art of Purring (David Michie): Here’s the second delightful novel on the further adventures of His Holiness’s Cat. Now this mischievous feline is searching for the true meaning of happiness—beyond the kind that comes and goes like a can of flaked tuna. This book’s inspiring lessons will surely make you purr!?15. The Last Laugh (Arjuna Ardagh): If you love fiction with a twist of self-empowering wit and wisdom, enjoy this beautifully written and charming story about a young man who meets a quirky guru who finds a way to crawl into this troubled man’s hardened heart and awakens his spirit. Lots of laughs and life lessons, too!?Hay House was founded in 1984 by Louise L. Hay as a way to self-publish her first two books, Heal Your Body and You Can Heal Your Life (YCHYL), both of which became bestsellers and established Louise as a leader in the New Age movement. To date, YCHYL has sold more than 16 million copies worldwide and has been published in 25 languages. Today, Hay House is committed to publishing products that have a positive self-help slant conducive to healing planet Earth."
title: "Top 15 Must-Read Books For 2014"
type: "article"
url: "http://www.healyourlife.com/author-hay-house/2014/01/wisdom/personal-growth/the-top-15-must-read-books-for-2014"
__proto__: Object
__defineGetter__: function __defineGetter__() { [native code] }
__defineSetter__: function __defineSetter__() { [native code] }
__lookupGetter__: function __lookupGetter__() { [native code] }
__lookupSetter__: function __lookupSetter__() { [native code] }
constructor: function Object() { [native code] }
hasOwnProperty: function hasOwnProperty() { [native code] }
isPrototypeOf: function isPrototypeOf() { [native code] }
propertyIsEnumerable: function propertyIsEnumerable() { [native code] }
toLocaleString: function toLocaleString() { [native code] }
toString: function toString() { [native code] }
valueOf: function valueOf() { [native code] }
get __proto__: function __proto__() { [native code] }
set __proto__: function __proto__() { [native code] }

but my valid json is as below :

{
  "author": "Hay House UK",
  "title": "Top 15 Must-Read Books For 2014",
  "text": "When a year ends, it’s like finishing a favorite book. You really don’t want it to end because you’re still savoring all the good parts, but you also want to wrap it up so you can start the next one.\nBefore we close this chapter on 2013, we’d like to share some of oy and You Can Heal Your Life (YCHYL), both of which became bestsellers and established Louise as a leader in the New Age movement. To date, YCHYL has sold more than 16 million copies worldwide and has been published in 25 languages. Today, Hay House is committed to publishing products that have a positive self-help slant conducive to healing planet Earth.",
  "images": [
    {
      "primary": "true",
      "caption": "Hay House",
      "url": "http://www.healyourlife.com/img/resize_cache/1067-hay_house_logo_keep_aspect_215x215.jpg"
    },
    {
      "caption": "top books for 2014 hay house",
      "url": "http://www.healyourlife.com/img/resize_cache/3667-Top_15_Must_Read_Books_For_2014_keep_aspect_374x215.jpg"
    }
  ],
  "date_created": "Wed, 01 Jan 2014 09:17:31 PST",
  "categories": {
    "entertainment_culture": 0.09647619047619045,
    "hospitality_recreation": 0.04541137315797972,
    "other": 0,
    "business_finance": 0.039999999999999994,
    "technology_internet": 0.014511842376414444,
    "socialissues": 0.07857142857142856,
    "sports": 0.05831770720339089,
    "humaninterest": 0.04666666666666667,
    "religion_belief": 0.03994037416667575,
    "war_conflict": 0.053333333333333316,
    "education": 0.13887284818770693,
    "health_medical_pharma": 0.09809523809523808,
    "labor": 0.048559733653411985,
    "law_crime": 0.01257142857142857,
    "politics": 0.12309533849221464,
    "environment": 0.08025982988254671,
    "weather": 0.013888095736801704,
    "disaster_accident": 0.011428571428571427
  },
  "html": "<div><div class=\"image_frame\"><img alt=\"Hay House\" src=\"http://www.healyourlife.com/img/resize_cache/1067-hay_house_logo_keep_aspect_215x215.jpg\"></img><div class=\"caption\">Hay House</div></div><div class=\"image_frame\"><img alt=\"top books for 2014 hay house\" height=\"215\" src=\"http://www.healyourlife.com/img/resize_cache/3667-Top_15_Must_Read_Books_For_2014_keep_aspect_374x215.jpg\" width=\"374\"></img><div class=\"caption\">top books for 2014 hay house</div></div><p>When a year ends, it&rsquo;s like finishing a favorite book. You really don&rsquo;t want it to end because you&rsquo;re still saank\">Mife. But she went one step further and collected scientific evidence to support wha together to meet the challenges and opportunities in the days ahead. And for our future leaders&mdash;GenYers (everyone else!), there are tips for you, too!</p><p>6. <a href=\"http://www.hayhouse.com/details.php?id=8326\" target=\"_blank\">Love Your Enemies</a>  learn how to identify the people who challenge you (even yourself!) and learn to transform your relationships with them.</p><p>7.&nbsp;<a href=\"http://www.hayhouse.com/details.php?id=9229\" target=\"_blank\">Forgiveness</a>(Iyanla Vanzant): Iyanla says that forgiveness will cure anything that ails you, and she has created a powerful program to help you to forgive evlishing products that have a positive self-help slant conducive to healing planet Earth.</p></div>",
  "supertags": [
    {
      "id": 18957,
      "positions": [
        [
          873,
          881
        ],
        [
          1093,
          1100
        ]
      ],
      "name": "Medicine",
      "score": 0.9,
      "contentMatch": 0.945054945054945,
      "categories": {
        "692348": "Medicine",
        "14500038": "Health Sciences"
      },
      "type": 1,
      "senseRank": 1,
      "variety": 0.2922374429223744,
      "depth": 0.7647058823529411
    },
    {
      "id": 201657,
      "positions": [
        [
          1592,
          1611
        ]
      ],
      "name": "Scientific evidence",
      "score": 0.8,
      "contentMatch": 0.2527472527472527,
      "categories": {
        "700292": "Scientific method",
        "13167332": "Sources of knowledge",
        "37407028": "Evidence"
      },
      "type": 1,
      "senseRank": 1,
      "variety": 0.817351598173516,
      "depth": 0.7058823529411764
    },
    {
      "id": 23315,
      "positions": [
        [
          982,
          988
        ],
        [
          1093,
          1107
        ],
        [
          1101,
          1107
        ],
        [
          1474,
          1477
        ],
        [
          1474,
          1476
        ]
      ],
      "name": "Physician",
      "score": 0.6,
      "contentMatch": 0.802197802197802,
      "categories": {
        "718247": "Physicians",
        "787658": "Occupations",
        "1006080": "Healthcare occupations"
      },
      "type": 1,
      "senseRank": 1,
      "variety": 0.3105022831050228,
      "depth": 0.7058823529411764
    }
  ],
  "type": "article",
  "date": "Wed, 1 Jan 2014 08:00:00 GMT",
  "cid": 1235024564,
  "url": "http://www.healyourlife.com/author-hay-house/2014/01/wisdom/personal-growth/the-top-15-must-read-books-for-2014"
}

I need that pure json and want to display that json onto page from javascript only, not including proto and all other properties.

like image 821
KomalJariwala Avatar asked Oct 02 '22 23:10

KomalJariwala


1 Answers

Take a look at the documentation: http://api.jquery.com/jquery.getjson/

It says:

The success callback is passed the returned data, which is typically a JavaScript object or array as defined by the JSON structure and parsed using the $.parseJSON() method. It is also passed the text status of the response.

Which means that the resulting JSON string will automatically be parsed to a JavaScript Object.

If you want the result to be in JSON format, you can use JSON.stringify() on the result:

function (data) {
    jsonData = JSON.stringify(data);
    console.log(jsonData);
    $("#test").text(jsonData);
});

However, now you would parse and stringify the JSON value unnecessary. If you are just interested in the string representation, you can just do the following:

$.ajax({
    dataType: "text",
    url: url,
    success: function (data) {
        console.log(data);
        $("#test").text(data);
    }
});

Remember, $.getJSON is just a shortcut for:

$.ajax({
    dataType: "json",
    url: url,
    data: data,
    success: success
});

So, by specifying dataType: "json", you tell jQuery, that you are expecting a JSON formatted string which then will automatically be parsed. If you specify dataType: "text" you should just get the text representation.

like image 140
basilikum Avatar answered Oct 17 '22 05:10

basilikum