import { search } from '@metrichor/jmespath';
import { DataReader } from './DataReader.js';
/**
 * Reads the value from a JSON document using the the JmesPath notation.
 * See https://jmespath.org/
 *
 * Note, after consideration this implementation is not used with API Client projects to extract
 * request data. Instead, we use `JsonReader` that converts the JSON to XML so the same
 * XPath can be used for both JSON and XML.
 */
export class JmespathReader extends DataReader {
    async getValue(path) {
        const body = await this.readPayloadAsString();
        if (!body) {
            return undefined;
        }
        let obj;
        try {
            obj = JSON.parse(body);
        }
        catch {
            return undefined;
        }
        return search(obj, path);
    }
}
//# sourceMappingURL=JmespathReader.js.map