Using a Forms but sending json instead

I’m trying to do something a little bit odd. I want to store some data in JSON (and one row as a text field) but for the html form I have set it up using typescript so people can add fields and then when they are done, It is bundled into a json and sent to django. Is there a correct way for my form to accept just JSON as a post request?

I’m using a different format for the html form because getting people to write their own JSON isn’t really ideal or fun.

Currently, if you want your Django view to accept JSON data, you would access the data using request.body.

You can then bind your form with the JSON object - but I’d be wondering why you’re trying to do it that way.

If these are all separate fields being accepted in the form, why does it matter how it’s being submitted? I would think it would only matter how that data is handled after it has been validated.

Sorry still a bit new to django. I’m coming from a perl (cataylst/dancer) background so normally I would just accept the JSON in view from the request body and do my own written validation. I was just wondering if there was a better/correct way to do it within django.

I think we need a better overall picture of what you’re trying to do here - and this includes what you’re going to do with this data after it has been submitted.

Sending post data to the server isn’t the end of this. Once the data is on the server and being handled by the view, what’s going to happen?

You want to look at this as a complete process when deciding how you want to handle it and what’s going to be done with it after being submitted.

At the moment it just gets chucked into a relational database. I was looking at adding some more validation later for the json but that was going to come later.

Are you storing it as JSON, or are you storing these fields as separate fields?

Is the JSON schema the same for all instances of this model? What does this schema look like?

What validation are you looking to perform?

What is the structure of the HTML form you’re using?