add option to extract keys and parse final element as json if it is a string