Home > Back-end >  In Jmeter, How to extract value from the variable having JSON data
In Jmeter, How to extract value from the variable having JSON data

Time:12-07

I am getting following response in one GET API call.

{
  "id": 78929,
  "created": "04-12-2021 02:37:52",
  "modified": "04-12-2021 02:37:52",
  "name": "Applebee",
  "url": "https://applebee-2.prashant.com",
  "key1": "vp_9d254bb754ab6283afa9ecf0f0847b5a",
  "interval2": 120,
  "tenant_id": 60895,
  "channel_id": 2,
  "channel_type": "platform",
  "warehouse_id": 54533,
  "warehouse_name": "Bedfordview Warehouse",
  "stock_policy": "CUSTOM",
  "currency_id": 45396,
  "order_from_date": "2021-10-03 02:36:48",
  "inventory_update": true,
  "order_update": true,
  "price_update": true,
  "active": true,
  "resync": true,
  "last_access_record_id": 89880,
  "last_accessed_record": {
    "id": 89880,
    "last_order_to_date": "2021-12-07T00:16:39.000 0000",
    "last_order_id": "0",
    "last_order_page": 1
  },
  "store_config": "{\"isOrderUpdateProcessor\":false,\"auto_archive\":true,\"tagOrderRisks\":true,\"error_emails\":\"[email protected]\",\"autoMapDuplicateProduct\":true,\"enabledMultiCurrency\":false,\"disableSyncPIIData\":false}",
  "last_inventory_sync": "04-12-2021 02:43:35",
  "inventory_sync_interval": 1440,
  "stock_policy_warehouse_ids": [
    {
      "id": 53543,
      "created": "04-12-2021 02:37:52",
      "modified": "04-12-2021 02:37:52",
      "store_id": 78929,
      "external_warehouse_id": "34639577171",
      "warehouse_id": 54533,
      "add_qty_value": "0%",
      "add_incoming_qty_value": "0%",
      "tenant_id": 60895
    },
    {
      "id": 53544,
      "created": "04-12-2021 02:37:52",
      "modified": "04-12-2021 02:37:52",
      "store_id": 78929,
      "external_warehouse_id": "60921610323",
      "warehouse_id": 54534,
      "add_qty_value": "0%",
      "add_incoming_qty_value": "0%",
      "tenant_id": 60895
    }
  ],
  "old_shopify_locations": [
    {
      "id": "60921610323",
      "name": "Supplier",
      "warehouseId": 54534,
      "warehouseName": "Lux"
    },
    {
      "id": "34639577171",
      "name": "Bedfordview Warehouse",
      "warehouseId": 54533,
      "warehouseName": "Bedfordview Warehouse"
    }
  ]
}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

I have added following JSON Extractor to fetch store_config value from the above API response.

enter image description here

So as per above example, I am getting following store_config value via JSON Extractor.

{
  "isOrderUpdateProcessor": false,
  "auto_archive": true,
  "tagOrderRisks": true,
  "error_emails": "[email protected]",
  "autoMapDuplicateProduct": true,
  "enabledMultiCurrency": false,
  "disableSyncPIIData": false
}
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

So Now, I want to fetch "isOrderUpdateProcessor" value from the above store_config varible.

So please help me into this.

CodePudding user response:

You can use another enter image description here

CodePudding user response:

Given you have groovy in your tags it would be something like:

vars.put('foo', new groovy.json.JsonSlurper().parseText(vars.get('StoreConfig')).isOrderUpdateProcessor as String)

More information:

  • Related