简体   繁体   English

对于jmeter post请求,如何从csv文件生成输入json?

[英]For jmeter post request, how can I generate input json from csv file?

I am trying to make a post rest call to my service. 我正在尝试对我的服务进行后期休息。 My sample input json file is, 我的示例输入json文件是,

{ "$id": "1", "description": "sfdasd" } {“$ id”:“1”,“description”:“sfdasd”}

I have one csv file which contain a bunch of id and description, So is there a option where I can convert csv file to json objects and pass them to post call? 我有一个csv文件,其中包含一堆id和描述,那么有没有一个选项,我可以将csv文件转换为json对象并将它们传递给post调用?

Assuming your CSV file is called test.csv , located in JMeter's "bin" folder and looks like: 假设您的CSV文件名为test.csv ,位于JMeter的“bin”文件夹中,如下所示:

CSV示例结构

  1. Add CSV Data Set Config to your Test Plan and configure it as follows: CSV数据集配置添加到测试计划并按如下方式进行配置:

    在此输入图像描述

  2. You can inline the defined JMeter Variables directly into your request body like: 您可以将定义的JMeter变量直接内联到您的请求体中,如:

     { "$id": "${id}", "description": "${description}" } 

    JMeter HTTP请求

  3. So when you run the test the variables placeholders will automatically be substituted with the values from the CSV file in the HTTP Request sampler: 因此,当您运行测试时,变量占位符将自动替换为HTTP请求采样器中CSV文件中的值:

    在此输入图像描述

See Using CSV DATA SET CONFIG article for more information on JMeter tests parameterization using CSV files. 有关使用 CSV文件进行JMeter测试参数化的更多信息,请参阅使用CSV DATA SET CONFIG文章。

Json is just text. Json只是文字。 Send as is with the variable id taken from csv: 使用从csv获取的变量id发送:

 { "${id}": "1", "description": "sfdasd" }

CSV data can be converted to JSON via a POJO using Jackson. 可以使用Jackson通过POJO将CSV数据转换为JSON。 If a POJO is not already defined or required, you can always use the Java Collection classes to store parsed data and later convert it to JSON. 如果尚未定义或要求POJO,则始终可以使用Java Collection类来存储已分析的数据,然后将其转换为JSON。 http://www.novixys.com/blog/convert-csv-json-java/ is a good reference on how to convert csv to java. http://www.novixys.com/blog/convert-csv-json-java/是如何将csv转换为java的一个很好的参考。 You can check the following links too. 您也可以查看以下链接。 1. directly convert CSV file to JSON file using the Jackson library 2. Converting an CSV file to a JSON object in Java 1. 使用Jackson库直接将CSV文件转换为JSON文件 2. 使用 Java将CSV文件转换为JSON对象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在JMeter的一个请求中从CSV文件发送完整的JSON数据 - Sending Complete JSON Data from the CSV file in one request in JMeter 如何在 Z8F0466AE1A66FDAF3CED537A2 中的单个 HTTP 请求中从 CSV 文件发送多个 JSON 数据 - How to send multiple JSON data from CSV file in single HTTP request in JMETER tool 如何使用 Python 从我的 CSV 文件中生成嵌套的 JSON 数据 - How can I use Python to generate nested JSON data from my CSV file 如何从Python中的csv文件生成JSON? - How to generate JSON from the csv file in Python? JMETER:如何在 Json 提取器中从 CSV 文件中添加值? - JMETER: How to add value from CSV file in Json Extractor? 如何从 POST 请求中获得干净的响应并将其保存在 json 文件中 - How can I get a clean response from POST request and save it in a json file 使用JMETER CSV日期设置配置时如何在请求正文中将CSV文件中的数据转换为JSON - How to have the data in the CSV file converted to JSON in the request body when using JMETER CSV Date set config 使用 JMeter 从 CSV 文件构建 JSON 批次 - Build JSON Batches from CSV file with JMeter Json的Jmeter CSV文件 - Jmeter CSV file for Json 如何在 Z4F8AAC143764B0646D 中使用 groovy 将来自 http 请求的 JSON 响应传递给 jsr223 断言 - How can I pass JSON response from http request to jsr223 assertion using groovy in Jmeter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM