Loading ...
Sorry, an error occurred while loading the content.

Re: Detecting if a Property of a JSON exists.

Expand Messages
  • luchkovsky
    ... To test it by JsonTools (http://sourceforge.net/projects/jsontools): var jTools = new JsonTools(); if ( jTools.getValue(object, path) != null ) { alert(
    Message 1 of 6 , Feb 14, 2007
    • 0 Attachment
      --- In json@yahoogroups.com, "Gabriel Landowski"
      <gabriel_landowski@...> wrote:
      >
      > With Javascript when a user updates the field of a form I update my
      > local JSON object with a "new_value" property equaling the new value
      > entered into the field.
      >
      > What is the best syntax to see if a "new_value" property exists for a
      > node?
      >
      > "if(json_obj.child_node.new_value)" doesn't seem to work.
      >
      > Regards
      >

      To test it by JsonTools (http://sourceforge.net/projects/jsontools):

      var jTools = new JsonTools();
      if ( jTools.getValue(object, path) != null )
      {
      alert( "property exists or property value is null" )
      }
    • Gabriel Landowski
      ... Okay - turned brain on and got: if(json_obj.child_node.new_value != undefined) Regards
      Message 2 of 6 , Feb 14, 2007
      • 0 Attachment
        > "if(json_obj.child_node.new_value)" doesn't seem to work.

        Okay - turned brain on and got:

        if(json_obj.child_node.new_value != undefined)

        Regards
      • Stephen M. McKamey
        Or if you re not sure if the property has ever been assigned: if ( undefined !=== typeof json_obj.child_node.new_value) { } ... [Non-text portions of this
        Message 3 of 6 , Feb 14, 2007
        • 0 Attachment
          Or if you're not sure if the property has ever been assigned:

          if ("undefined" !=== typeof json_obj.child_node.new_value) { }


          On 2/14/07, Gabriel Landowski <gabriel_landowski@...> wrote:
          >
          > > "if(json_obj.child_node.new_value)" doesn't seem to work.
          >
          > Okay - turned brain on and got:
          >
          > if(json_obj.child_node.new_value != undefined)
          >
          > Regards
          >
          >
          >


          [Non-text portions of this message have been removed]
        • Gabriel Landowski
          ... Thanks
          Message 4 of 6 , Feb 15, 2007
          • 0 Attachment
            > Or if you're not sure if the property has ever been assigned:
            > if ("undefined" !=== typeof json_obj.child_node.new_value) { }

            Thanks
          Your message has been successfully submitted and would be delivered to recipients shortly.