Json Response to CSV Conversion

1,124 views
Skip to first unread message

shreehar...@gmail.com

unread,
Nov 20, 2019, 5:17:10 AM11/20/19
to jmeter-plugins
Hi All,

I have a JSON output like 
{
    "cc_device":     {
        "device_type_name": "System c3000",
        "product_number": "43750",
        "os_name": "UNKNOWN",
        "os_version": "UNKNOWN",
        "protocol_type_name": "OA",
        "firmware_version": "N/A",
        "host_name": "Perf2.hpe.5whxpehqejco",
        "serial_no": "Perf2solcxM2NW63CQEG",
        "ip_address": "1.1.1.1"
    }

and want the convert the JSON output and Store in CSV file like below

Outputcsv.png

Looking for plugin or script for Json to CSV conversion

Thanks

Shri



gli...@gmail.com

unread,
Nov 20, 2019, 12:08:39 PM11/20/19
to jmeter-plugins
I don't know where this "ClientID" comes from, the other values can be extracted/written as follows:

    1. Add JSR223 PostProcessor as a child of the request which returns the above JSON
    2. Put the following code into "Script" area:
def json = new groovy.json.JsonSlurper().parse(prev.getResponseData()).cc_device
new File('somefile.csv') << json.host_name << ',' << json.serial_no  <<',' << json.device_type_name << ',' << json.product_number << ',' << json.os_name << ',' << json.os_version << ',' << json.protocol_type_name << System.getProperty('line.separator')

Shriharsh Desai

unread,
Nov 21, 2019, 1:08:28 AM11/21/19
to jmeter-...@googlegroups.com
Thank you. It worked, but no Labels in the output file.

Could you please help.

Perf2.hpe.bmqtksrdxjse Perf2solcxB0FJ4232KR BladeSystem c3000 Enclosure 437502-B21 UNKNOWN UNKNOWN OA
Perf2.hpe.hftfb82zh9t2 Perf2solcxKIFDEDEEVF BladeSystem c3000 Enclosure 437502-B21 UNKNOWN UNKNOWN OA

Thanks
Shri

--
You received this message because you are subscribed to a topic in the Google Groups "jmeter-plugins" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jmeter-plugins/M7xbXf9LykM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jmeter-plugin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jmeter-plugins/14326aa1-aa22-48fc-bebc-b10a7fed9fca%40googlegroups.com.

Shriharsh Desai

unread,
Nov 21, 2019, 4:56:47 AM11/21/19
to jmeter-...@googlegroups.com
Hi,

I modified the script as below

def json = new groovy.json.JsonSlurper().parse(prev.getResponseData()).cc_device

new File('C:/results/Coll_Response_${__time(yyyy-MM-dd-HHmm)}.csv') << "Host Name" << ',' << "Serial Number" << ',' << "Device Type Name" << ',' << "Product Number" << ',' << "OS Name" << ',' << "OS Version" << System.getProperty('line.separator') << json.host_name << ',' << json.serial_no  <<',' << json.device_type_name << ',' << json.product_number << ',' << json.os_name << ',' << json.os_version << ',' << json.protocol_type_name << System.getProperty('line.separator')

But , it is showed the LABEL , but 10 iterations , it is showing labels 10 times

Host Name Serial Number Device Type Name Product Number OS Name OS Version
Perf2.hpe.pcn5vfvr1k9t Perf2solcx5A8DGRWRMT
BladeSystem c3000 Enclosure 437502-B21 UNKNOWN UNKNOWN OA
Host Name Serial Number Device Type Name Product Number OS Name OS Version
Perf2.hpe.72470a9oecza Perf2solcxYDJRJ3Q9RP
BladeSystem c3000 Enclosure 437502-B21 UNKNOWN UNKNOWN OA
Host Name Serial Number Device Type Name Product Number OS Name OS Version
Perf2.hpe.bny36d3qfu1v Perf2solcxPOLNAJXST2
BladeSystem c3000 Enclosure 437502-B21 UNKNOWN UNKNOWN OA
Host Name Serial Number Device Type Name Product Number OS Name OS Version
Perf2.hpe.x5ghf2986ruf Perf2solcxZUUKOFDSVF
BladeSystem c3000 Enclosure 437502-B21 UNKNOWN UNKNOWN OA
Host Name Serial Number Device Type Name Product Number OS Name OS Version
Perf2.hpe.6fi4atxrp0rb Perf2solcxMPGJERXLK9
BladeSystem c3000 Enclosure 437502-B21 UNKNOWN UNKNOWN OA

I want to show label only once.

And another help, I want to store ONLY FILE NAME (CC_Coll_Response_2019-11-21-1513.csv) in to c:/temp/response.csv file

Thanks
Shri




Vincent Daburon

unread,
Nov 21, 2019, 5:37:29 AM11/21/19
to jmeter-plugins
Hi,
Another solution is to use the Http Simple Table Server.

Get informations from your JSON, this grooy script, JSON Path Extractor or classical Regular Extractor or Boundary extractor

Create a string for 1 line that contains your informations and ADD this line to the Http Simple Table Server.
Example line
LINE=Perf2.hpe.5whxpehqejco;Perf2solcxM2NW63CQEG;client_id;System c3000;43750;UNKNOWN;UNKNOWN;OA
Save the result in a file at the end of the test with command SAVE.

This solution is thead safe.

Regards.
Vincent DAB

Shriharsh Desai

unread,
Nov 22, 2019, 5:42:08 AM11/22/19
to jmeter-...@googlegroups.com
Hi All,

I have a requirement in Jmeter. I'm writing output to a file with time stamp. Below is the script

def json = new groovy.json.JsonSlurper().parse(prev.getResponseData()).cc_device

new File('C:/CC/results/CC_Coll_Response_${__time(yyyy-MM-dd-HHmm)}.csv') << json.host_name << ',' << json.serial_no  <<',' << json.device_type_name << ',' << json.product_number << ',' << json.os_name << ',' << json.os_version << ',' << json.protocol_type_name << System.getProperty('line.separator')

Example File Name like : CC_Coll_Response_2019-11-22-1603.csv is created in C:\CC\results folder.

I want to use the above file name and its Json content (like Host_Name) in next API to trigger.

As it post fix with a time stamp. It keeps changing. 

Need help on how to extract Dynamic File Name and content.

Thanks
Shri 


--
You received this message because you are subscribed to a topic in the Google Groups "jmeter-plugins" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jmeter-plugins/M7xbXf9LykM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jmeter-plugin...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages