Creating JSON string dynamically based on field contents

I am having an issue dynamically creating a JSON string that will be passed to our API to execute an UPDATE on the database.

Use Case: employee data record
Action: User clicks the Update button, some data validation happens, then the JSON string is created to be passed to the API.

**creating the JSON string is not the issue…but determining what goes in it (or does not, as I will describe) is the tricky part.

This technique has been working very well in our solution…until some of the fields on the container are empty (or need to be) and I try to update the db. I get a data type mismatch because I’m passing null and the db is looking for data.

So the obvious answer is to only pass fields that have data for the update…which creates another set of problems.

  1. What is the quick and easy way to populate a dictionary or array with the fields in my container which have data so they can be iterated through to construct the JSON string?

  2. How do I “empty” a field in the database record without passing null? Example: Joe has two address lines: 123 Main St, and Box 123. If he no longer needs the “box 123” line, what is the syntax to pass to the DB to get that field data removed?

I’m sure this is a common use case…but I can’t find anything in the forum that answers it. I hope I have explained this thoroughly. If not, please ask questions.

Thanks!

If it’s NULL, either send an empty string “” or make sure that the database field is setup to allow NULL and then just pass the NULL (I think that should work)