ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

YAJL and Null field

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • YAJL and Null field

    Good Day,

    So we have a json field being passed as:

    "workord_number" : null

    This is what I see in the json file as text.

    In my RPGLE program it is written as:

    node = yajl_object_find( docNode: 'workord_number' );
    If Node <> *Null;
    dshdr.workord_number = yajl_get_string(node);
    endif;


    The above JSON does not return *Null, it is determined as NOT *NULL and processed as blank.

    Is there anything else in the object capture we should be doing to see it as *Null?
    If the workord_number is not present in the passed JSON string then it comes in as *Null

    Thnx
    Bill
    Bill
    "A good friend will bail you out of jail,
    A true friend would be sitting beside you saying,
    'Wow, that was fun.'"

  • #2
    yajl_object_find will only return *Null (i.e. a null pointer) when it cannot find a node with the requested name. In this case the name is found so the node pointer is set.

    I think what you need is YAJL_IS_NULL like so:

    If Not YAJL_IS_NULL(Node); // This should work when *Null or pointing to a null value

    Instead of your If Node <> *Null;

    Comment


    • #3
      Thnx.

      So I did this:

      If Not YAJL_IS_NULL(Node) and
      Node <> *Null;
      // good data
      Else;
      // No data
      Endif;

      Seems to do what I expected.

      Thnx again
      Bill
      Bill
      "A good friend will bail you out of jail,
      A true friend would be sitting beside you saying,
      'Wow, that was fun.'"

      Comment


      • #4
        Glad it worked - but I think the "and Node <> *Null; " bit is superfluous and a bit misleading for those who come after. Would also be a good idea to add parentheses around the conditions to make it obvious where the NOT and the AND belong. But maybe that I'm being pedantic and that si the teacher in me.

        Comment


        • #5
          In testing if I did not pass the json string ( IE: true *Null ) and only had
          If Not YAJL_IS_NULL(Node),
          it passed thru the good data returning blank.
          Bill
          "A good friend will bail you out of jail,
          A true friend would be sitting beside you saying,
          'Wow, that was fun.'"

          Comment


          • #6
            So if you do this:
            Code:
            If YAJL_IS_NULL(Node)
              // I have no data
            Else;
            // I have data
            Endif;
            You're saying that it goes to the Else ?? NOw I think about it I guess it would since the result is not a JSON null <doh!> No I'm the one getting mixed up as to null and *Null.
            I think to make it obvious I'd be inclined to do it like this:
            Code:
            If Node = *Null or YAJL_IS_NULL(Node);
              // I have no data
            Else;
            // I have data
            Endif;
            Mostly because I'm not wild about using NOT conditions unless I need to.
            Last edited by JonBoy; January 15, 2019, 05:23 PM.

            Comment

            Working...
            X