Menu

toJSON properties

Help
2006-03-24
2013-04-22
  • Russell Jones

    Russell Jones - 2006-03-24

    Having sent a moderately complex object (an array with each element an array of objects from mysqli_fetch_object($rs) or an empty array ) I have found that when iterrating over the objects in JS with "for (x in y)" they have the property toJSON. Is this normal? If so, is there some way to get rid of these properties, or are they required for re-serialisation? If the latter, is it be possible to declare that one has no interest in reserialising the returned object to avoid the extra property?

     
    • Craig Mason-Jones

      The toJSON property is added to the prototypes of the various types that are JSON-encodable in the jsolait library, which is why you are seeing them on the JSON-decoded objects. Is it possible to just ignore them, or is there some reason that you need to access each property of each item?

      Yours,
      Craig

       
      • Russell Jones

        Russell Jones - 2006-04-05

        I don't need to strictly, but it's often convenient to iterate over the properties of an object. I guess I could use typeof() to skip functions, or perhaps even figure out a way to determine that it's a prototype function (I forget exactly how the inheritance-like chain of prototypes thing works in JS). Still, it'd be nice to have a function to call to get just the values, or a parameter to the call that would prevent the toJSON function from being added.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.