Json filetype in (Contact)form with flex

@Karmalakas thanks for the answer. I took this as a start and finally found a solution.
The twig makes from a contact form a json record. I generate a unique random code as key.

{% macro render_field(form, fields) %}
{% set record = [ ] %}
{% for index, field in fields %}
{% set value = form.value(field.name) %}
{% set veld = field.label ~ ':' %} 
{% set record = record|merge([veld, value]) %}
{% endfor %}
{% set code = random_string(15)|md5 %}
{{ { (code): record}|json_encode|raw }}  
{% endmacro %}
{{ _self.render_field(form, form.fields) }}

However, when I try to read these records as a database by a flex object it fails.
I don’t know the solution for this or is the twig not good? Who does?

Or is there another solution that can be created FI a twig file where a front-end form can be presented as a flex-object?