使用Jmeter提取JSON值

时间:2017-05-15 11:53:09

标签: json jmeter extract

我有这个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"
  }
}

我尝试使用Jmeter来提取agentID的值,我怎么能用Jmeter来做,哪个更好?使用提取器或json提取器?

我想要做的是提取agentID值以便在另一个http请求示例中使用它,但首先我必须从此请求中提取它。

谢谢!

1 个答案:

答案 0 :(得分:1)

我认为使用JSON Extractor是获取此agentID值的最佳方式,相关的JsonPath查询将像$..agentID一样简单

演示:

JMeter Json Extractor Demo

请参阅以下参考资料: