0

I have this JSON:

{
  "totalMemory" : 12206567424,
  "totalProcessors" : 4,
  "version" : "0.4.1",
  "agent" : {
    "reconnectRetrySec" : 5,
    "agentName" : "1001",
    "checkRecovery" : false,
    "backPressure" : 10000,
    "throttler" : 100
  },
  "logPath" : "/eq/equalum/eqagent-0.4.1.0-SNAPSHOT/logs",
  "startTime" : 1494837249902,
  "status" : {
    "current" : "active",
    "currentMessage" : null,
    "previous" : "pending",
    "previousMessage" : "Recovery:Starting pipelines"
  },
  "autoStart" : false,
  "recovery" : {
    "agentName" : "1001",
    "partitionInfo" : { },
    "topicToInitialCapturePosition" : { }
  },
  "sources" : [ {
    "dataSource" : "oracle",
    "name" : "oracle_source",
    "captureType" : "directOverApi",
    "streams" : [ ],
    "idlePollingFreqMs" : 100,
    "status" : {
      "current" : "active",
      "currentMessage" : null,
      "previous" : "pending",
      "previousMessage" : "Trying to init storage"
    },
    "host" : "192.168.191.5",
    "metricsType" : { },
    "bulkSize" : 10000,
    "user" : "STACK",
    "password" : "********",
    "port" : 1521,
    "service" : "equalum",
    "heartbeatPeriodInMillis" : 1000,
    "lagObjective" : 1,
    "dataSource" : "oracle"
  } ],
  "upTime" : "157 min, 0 sec",
  "build" : "0-SNAPSHOT",
  "target" : {
    "targetType" : "equalum",
    "agentID" : 1001,
    "engineServers" : "192.168.56.100:9000",
    "kafkaOptions" : null,
    "eventsServers" : "192.168.56.100:9999",
    "jaasConfigurationPath" : null,
    "securityProtocol" : "PLAINTEXT",
    "stateMonitorTopic" : "_state_change",
    "targetType" : "equalum",
    "status" : {
      "current" : "active",
      "currentMessage" : null,
      "previous" : "pending",
      "previousMessage" : "Recovery:Starting pipelines"
    },
    "serializationFormat" : "avroBinary"
  }
}

I trying using Jmeter to extract out the value of agentID, how can I do that using Jmeter, what would be better ? using extractor or json extractor?

what I am trying to do is to extract agentID value in order to use it on another http request sample, but first I have to extract it from this request.

thanks!

1 Answer 1

1

I believe using JSON Extractor is the best way to get this agentID value, the relevant JsonPath query will be as simple as $..agentID

Demo:

JMeter Json Extractor Demo

See the following reference material:

Sign up to request clarification or add additional context in comments.

4 Comments

And if I want to use code in order to parse the json how can I do that using jmeter?
You can add JSR223 PostProcessor as a child of the request which returns above JSON and put the following line into "Script" area: log.info("agentID: " + com.jayway.jsonpath.JsonPath.parse(prev.getResponseDataAsString()).read('$..agentID')[0]). It will print "agentID" value into jmeter.log file. See Parsing and producing JSON - Groovy and Groovy is the New Black articles for more details.
Thanks but what I meant was can I add java code which will parse json strings?
Groovy is Java-compatible so you can treat above as plain Java code (actually it doesn't use any Groovy syntax features)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.