FoxPro Programming
VFP Illegal Object Name
Gravatar is a globally recognized avatar based on your email address. VFP Illegal Object Name
  Gregg B
  All
  Sep 24, 2024 @ 08:14am

I am trying to translate data from a web hook into VFP data. The JSON coming in looks like this:

{
  "flowID": "blocktrust-network",
  "id": "AJP4RROTUemd86C4j4Bd",
  "createdAt": "2024-09-23T18:45:12.892Z",
  "fields": {
    "first_name": "Gregg",
    "last_name": "Bcbvnv",
    "email_address": "greggggchgygvcjfehdhg.barfield@ledgerspace.net",
    "phone": "979 219 3451",
    "zip": "77845",
    "sale_date": "10/9/2024",
    "auction_type": "JRS Livestock Auction",
    "special_program": "JRS Stocker Vac",
    "gender_selling": "All Steers",
    "number_steers": "56",
    "base_weight": "600",
    "breed": "Angus, Hereford",
    "days_weaned": "45 Days",
    "management": "Dehorned, Bunk Broke",
    "Please choose an option": "No, they are not tagged.",
    "comments_upload-1": "RE Follow up.pdf",
    "comments_upload-1_file": "https://builder.prd.heyflow.com/dl/e631e4c13322439f5b12c32bd006c3e5f3bafba23675c105537a85f4af8bea50"
  }
}

I need to get that URL out of the "comments_upload-1_file" but this code always throws an error. I am guessing because of the dash which VFP thinks is a subtraction symbol and deems it illegal:

STORE loObj2.fields.comments_upload-1_file to upload_file_var

Obviously, the name is out of my control or I would just change it. Can you think of a workaround using West-Wind tools or any other VFP function?

Gravatar is a globally recognized avatar based on your email address. re: VFP Illegal Object Name
  Rick Strahl
  Gregg B
  Sep 24, 2024 @ 08:30am

Yes, the field name is invalid - the JSON property has a name that's not allowed in FoxPro (and in JavaScript only via a object["named-property"] map expression).

IAC, you can't access it using the original name, but wwJsonSerializer strips out invalid characters. Figuring out what it ends up being is a bit tricky - you'll have to use the debugger:

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: VFP Illegal Object Name
  Gregg B
  Rick Strahl
  Sep 24, 2024 @ 08:56am

That's perfect. Thanks, Rick. You're a champ.

© 1996-2024