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

Re: Detecting if a Property of a JSON exists.

Expand Messages
  • luchkovsky
    ... I recommend you to try JsonTools http://sourceforge.net/projects/jsontools new JsonTools().setValue(object, path , newValue) The path defines a way to
    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
      >

      I recommend you to try JsonTools http://sourceforge.net/projects/jsontools

      new JsonTools().setValue(object, "path", newValue)

      The path defines a way to compute a place in JSON model.
      If nodes in the path are missed they will be created with
      corresponding to path type (Object or Array).

      JsonTools include methods of populating data from HTML form to JSON
      and the contrary:
      Fills the HTML form with corresponding structure from JSON model.
      Applies corresponding form data to JSON model.

      Good luck
    • luchkovsky
      ... To test it by JsonTools (http://sourceforge.net/projects/jsontools): var jTools = new JsonTools(); if ( jTools.getValue(object, path) != null ) { alert(
      Message 2 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 3 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 4 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 5 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.