Be very wary attempting to parse json with general shell tools. There is a very specific tool for this job called jq (json query), which handles json and json arrays properly. That said, if "name" only appears once in the file, you can safely use the following expression to substitute $username, sed "/\"name\":/s/\(^[^:]*[:][ ]\).*$/\1\"$username\",/"
Based on the example, it should be sed 's/"name":.*/"name" : '${username}'/g' instead. You'll also need to take care of potential extra spaces after the quotes. Goes on to say you shouldn't attempt parsing with the wrong tools.
jq(json query), which handles json and json arrays properly. That said, if"name"only appears once in the file, you can safely use the following expression to substitute$username,sed "/\"name\":/s/\(^[^:]*[:][ ]\).*$/\1\"$username\",/"