Not sure when it started, but in SQL Server 2019 you can use FOR JSON AUTO:
select LEFT(@@VERSION,38) as "SQL Server Version is" ,p.person_id ,p.person_name ,a.pet_id ,a.pet_name from @Persons p join @Pets a on p.person_id = a.pet_owner FOR JSON AUTO
Result: [ { "SQL Server Version is": "Microsoft SQL Server 2019 (RTM-CU28-GD", "person_id": 2, "person_name": "Jack", "a": [ { "pet_id": 4, "pet_name": "Bug" }, { "pet_id": 5, "pet_name": "Feature" } ] }, { "SQL Server Version is": "Microsoft SQL Server 2019 (RTM-CU28-GD", "person_id": 3, "person_name": "Jill", "a": [ { "pet_id": 6, "pet_name": "Fiend" } ] } ]