Web Connection
json serializer question
Gravatar is a globally recognized avatar based on your email address. json serializer question
  Ron Jasper
  All
  Aug 28, 2025 @ 09:17am

Hi Rick, The following code is working, it's just that on my live webconnection server I'm getting a text file with "false", but on my test local machine I get fully formatted json. Is there something missing on my live server? I've captured the object type and the resultant string to a cursor which I then save. On my local machine the string is formatted JSON but on my live server the lojsonSerializer.serialize method produces text that says "false".

FUNCTION l_readFromLswhSaleUpdate
LPARAMETERS po_loFromLsSaleUpdate
CREATE CURSOR check_structure (objstruc M(4))
LOCAL loJsonSerializer, lcJson
loJsonSerializer = CREATEOBJECT("wwJsonSerializer")
m.objstruc = TYPE('loJsonSerializer')
INSERT INTO check_structure FROM MEMVAR 
lcJson = loJsonSerializer.serialize(po_loFromLsSaleUpdate)
m.objstruc = lcJson
INSERT INTO check_structure FROM MEMVAR
SELECT check_structure
COPY TO check_structure
STRTOFILE(lcJson,"lsjson\l_"+GetUniqueId()+".txt")
Response.Status = "204 No Content"
RELEASE loJsonSerializer, lcJson
RETURN
ENDFUNC
Gravatar is a globally recognized avatar based on your email address. re: json serializer question
  Ron Jasper
  Ron Jasper
  Aug 29, 2025 @ 03:40am

Hi again Rick, I just want to confirm that as long as the function in the restful API on the Web Connection receives a valid JSON object as a parameter that Web Connection will recognize it. I'm in touch with one of the technical leads at the cloud-based point-of-sale company this morning to do further trouble-shooting. Web Connection is saying the passed parameter is not an object. I can see that in the Web Connection server log. Any thoughts? As always, your assistance is greatly appreciated, thanks.

Gravatar is a globally recognized avatar based on your email address. re: json serializer question
  Ron Jasper
  Ron Jasper
  Aug 29, 2025 @ 05:19am

Hi Rick, The cloud-based point-of-sale is sending me application/x-www-form-urlencoded instead of a JSON object. The JSON object is contained within a field called "payload". Could you please suggest the way I can deal with capturing the "payload" field and saving it to disk as a text file. I will have a timer-based app grab the text field from the disk, turn it into an object using JSONserializer.serialize and then parse it. Sorry for my confusion(s).

Gravatar is a globally recognized avatar based on your email address. re: json serializer question
  Carl Chambers
  Ron Jasper
  Aug 29, 2025 @ 08:31am

Hi Ron,

Did you try Request.Form("payload") ?

Gravatar is a globally recognized avatar based on your email address. re: json serializer question
  Ron Jasper
  Carl Chambers
  Aug 29, 2025 @ 08:49am

Hi Rick,

I ended up using:

lcPayload = Request.Params("payload") and then STRTOFILE(lcPayload,"lsjson\l_"+GetUniqueId()+".txt") which worked perfectly.

Is Request.form better than request.params?

Thanks again

Gravatar is a globally recognized avatar based on your email address. re: json serializer question
  Carl Chambers
  Ron Jasper
  Aug 29, 2025 @ 09:59am

Hi Ron,

Take a look at the source code for wwRequest.prg.
Request.Params() is a wrapper for checking the different possible places where the parameter my be passed and Request.Form() is the first place it looks.
It's handy if there is uncertainty about how a parameter will be passed.

Since you know "payload" is coming as a form variable, you can use Request.Form("payload").
It's unlikely that they will change their app later and pass a JSON payload in the querystring, so you're likely pretty safe with that.

There's no harm is calling Request.Params("payload") (performance difference is zero).

The benefit of calling Request.Form("payload") is, if you're looking at your code 5 years from now, it's immediately clear how the payload is being passed (if that matters to you).

Carl

Gravatar is a globally recognized avatar based on your email address. re: json serializer question
  Ron Jasper
  Carl Chambers
  Aug 29, 2025 @ 12:59pm

Thanks Carl, appreciate the insight.

© 1996-2025