JMeter-如何读取JSON文件? [英] JMeter - How to read JSON file?
问题描述
我在JMeter中为数据文件使用了CSV格式.我们的副总裁希望将格式更改为JSON.如何从磁盘读取JSON文件?
I used the CSV format for the data files in JMeter. Our VP wants to change the format to JSON. How can I read a JSON file from the disk?
推荐答案
您至少有2个选择:
-
使用 HTTP请求采样器和
file
协议,例如:
Use HTTP Request sampler and
file
protocol like:
JSON文件基本上是纯文本文件,因此您可以使用 JSON提取器或 JSON路径提取器来解析JSON数据并将结果存储到 JMeter变量供以后重用
JSON files are basically plain-text files so you will be able to use JSON Extractor or JSON Path Extractor to parse JSON data and store the result into JMeter Variables for later reuse
参考文献:
- Jayway JsonPath - Getting Started
- Advanced Usage of the JSON Path Extractor in JMeter
使用 JSR223测试元素和Groovy语言. Groovy通过 JsonSlurper 内置了JSON支持.因此您将能够以编程方式解析JSON文件.
Use JSR223 Test Elements and Groovy language. Groovy has built-in JSON support via JsonSlurper so you will be able to parse the JSON file programmatically.
参考:
- Groovy编程语言-解析并生成JSON
- Groovy-JSON
- The Groovy programming language - Parsing and producing JSON
- Groovy - JSON
这篇关于JMeter-如何读取JSON文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!