Define linksoutside the loop:
var links = [];
$(".link").each(function() {
group += 1;
text += 1;
links[group] = [];
links[group][text] = $(this).val();
});
var jsonLinks = $.toJSON(links);
I should also point out that this does not make much sense, because you get element 7, for example, being an array with one element (with index 7). Is this really what you want?
I think what you want is an array of values. If so, why not use it map()?
var links = $(".link").map(function(i, val) {
return $(val).val();
});