I have a custom page builder for a client, where-by they can build out their own web forms via a drag and drop back-end.
At the moment, I can get the data to output in a JSON format such as the following:
{
"email":"[email protected]",
"geoip_country":"XXYY",
"geoip_state":"XXYY",
"geoip_city":"XXYY",
}
But, I need to alter the output in the following format, I'd like to seperate out the email field from the form, and drop all other data nested inside the dynamic_attributes section, like this:
{
"email":"[email protected]",
"dynamic_attributes":{
"geoip_country":"XXYY",
"geoip_state":"XXYY",
"geoip_city":"XXYY",
// all other form fields here.
},
}
Could anyone point me in the right direction? I'm not hugely experienced with outputting JSON - I should also add that the json is being created from the following jQuery function:
(function ($) {
$.fn.serializeFormJSON = function () {
var o = {};
var a = this.serializeArray();
$.each(a, function () {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
})(jQuery);
See Fiddle: https://jsfiddle.net/fish_r/m46zLdo9/3/
Thanks!
dynamic_attributesa constant property name? If not where would that property name come from? How are fields separated as primary or children? Show some sample htmlemailand all others are nested? I suspect there is a higher level of complexity than that no?