Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

HTTP_Resource_Services processing null (emptystring)

Don,

A ‘POST’ is being sent to my api and I am calling HTTP_Resource_Services with ‘PostDatabaseItem’ as the service.
All the null (emptystring) values are being processed as data with ‘null’ not blank.

As the call to HTTP_Resource_Services with ‘GetDatabaseItems’ creates emptystring as null, then, as the web developer is returning this same data with any new values filled, the PostDatabaseItem should interpret this as an emptystring

This is a sample of the data that is being sent to me.

................."applicant_given_name":null,"applicant_middle_name":null,......................


I added this:

Body = HTTP_Services('GetHTTPPostString')
Body = HTTP_Services('DecodePercentString', Body)
if Body then TxtRequest:=CRLF$:CRLF$:Body

to the debug_tools section of HTTP_MCP to see the data passed in.


Hoping that all my terminology is followable,

Can you help me as to where the problem lies.

see attached log file.

Comments

  • edited December 2015
    Barry,

    It is important to understand that in JSON, null and empty string are two different things. A null value in JSON would look like this:

    {"field": null}

    Whereas an empty string would look like this:

    {"field": ""}

    Of course, the following would simply be the word "null" as a string:

    {"field": "null"}

    The PostDatabaseItem service relies upon the SRP_JSON GETVALUE service to extract the value from your JSON object. If your JSON object contains the keyword null (i.e., without quotes) then the word "null" is what gets returned by the GETVALUE service so you have a way of knowing that no value was returned verses an empty string value.

    Right now you have two choices to make this work in a way that might better suit your needs. First, you can update the PostDatabaseItem service yourself to swap all instances of "null" with "" whenever you use the GETVALUE service. Second, you can ask your Javascript developer to return an empty string instead of null.

    There is a third option, but it is not available as of yet. When we began encountering this issue ourselves we wondered if there was a better way to approach this. We have a new version of SRP Utilities which has not yet been released that supports a fourth argument for the GETVALUE service. In this argument you can specify exactly what you want returned if the null keyword is used. In our case, we specify the empty string as so:

    Value = SRP_JSON(hJSON, 'GETVALUE', FieldName, '')

    I imagine this will be released in the near future, probably in the next week or two.
  • Thank you, I have implemented choice #1

    Please advise when updated version of SRP_JSON is available and I will implement that. (In case null is ever a valid data field). I assume there will be a distinction made between null, and "null",


  • Barry,

    Just stay tuned to the normal information channels (Blog, Newsletter, Facebook, Twitter) and you'll see any announcement we post about this.

    I don't follow your comment about a distinction between null and "null". Please elaborate on this.
  • (say)
    "mydatafield": null, -> should return ""

    "mydatafield": "null", ->should return "null"
  • I assume you are referring to the GETVALUE service changes. Well, "null" will always return "null" because it is a string. That is how it works now and how it will work in the future.

    So the only question is how the null object type will be treated. As noted above, you get to decide this using the new override argument. However, if you leave that argument alone, the default return value will be "<null>". This is a slight change from the current version that omitted the angle brackets. We reasoned that the word "null" by itself was too common.
Sign In or Register to comment.