Rafiq Shaikh
Rafiq Shaikh

Reputation: 113

jmeter Reading Json data from file using JSR223, converting braces to square bracketconverting

I am using jmeter 5.1 in windows 10, in my jmeter test plan i am reading json data from file, after reading, i am using log.info ${sdata} to log the messages, but the output is converted the braces { to square bracket [, could someone tell me what's wrong.

Below is the data which the json file contains

{"name":"Foo Bar","year":"2018","timestamp":"2018-03-08T00:00:00","tags":["person","employee"],"grade":3.14}

{
    "name": "Foo Bar",
    "year": "2018",
    "timestamp": "2018-03-08T00:00:00",
    "tags": [
        "person",
        "employee"
    ],
    "grade": 3.14
}

Below is the line which i have in JSR223 Prepocessor to read the file and log it in info

def sdata = new groovy.json.JsonSlurper().parseText(new File("data.json").text)
log.info "$sdata"

And below is the output of log.info

["name":"Foo Bar","year":"2018","timestamp":"2018-03-08T00:00:00","tags":["person","employee"],"grade":3.14]

[
    "name": "Foo Bar",
    "year": "2018",
    "timestamp": "2018-03-08T00:00:00",
    "tags": [
        "person",
        "employee"
    ],
    "grade": 3.14
]

In the above output, the braces { got replaced to square bracket [

Please help

Upvotes: 1

Views: 564

Answers (1)

Dmitri T
Dmitri T

Reputation: 168072

This happens because you're basically printing a textual representation of LazyMap

If you want to see the same JSON as in the input you should create a JsonBuilder class instance and pass the "slurped" object to it.

Change this line:

log.info "$sdata"

to this one:

log.info(new groovy.json.JsonBuilder(sdata).toPrettyString())

More information:

Upvotes: 1

Related Questions