Here we are storing a group data as json encode to database.Since Json Encode is inbuilt with magento.
We have two values that must stored as value and key .So its a array
for ($i = 0; $i < $length; $i++) {
$productData = [
'form_key' => $this->formKey->getFormKey(),
'product' => $id,
'qty' => $params['qty'][$i]
];
$lengtharray[$i]['length'] = $params['length'][$i];
$lengtharray[$i]['qty'] = $params['qty'][$i];
}
}
here we get the values stored as ‘length’ and key as ‘qty’.
this can be written with
json_encode($lengtharray) into a database field.

the values will be stored as like above shown in the length field.