factor out json data extraction logic into separate function