Updated flag detection for installed packages and added ast conversion if json fails