added ability to add ?json flag only if we work with dir