Extract directory name for mkdir_p

Otherwise it creates 'data.json' dir and fails to save fetched data later...