JSON路径抽出:JSON路径表达式

问题描述:

应该是什么JSON路径表达式来获得JSON路径抽出:JSON路径表达式

beneficiaryType = OtherBankCustomer. 
My Json response is as follows: 
{ 
    "busBeneficiaryBeanList": [{ 
     "beneficiary_serial_no": 0, 
     "beneficiary_id": "2090", 
     "senderMobileNo": null, 
     "beneficiaryName": "Shibashish Dash", 
     "beneficiaryNickName": "Shib", 
     "beneficiaryType": "WalletCustomer", 
     "beneficiaryMobileNo": "9778697852", 
     "status": "Active", 
     "time": null, 
     "accountno": "8093630503", 
     "ifsccode": null, 
     "bankType": null, 
     "bankName": null, 
     "address1": "testtesttest", 
     "address2": "ewretrytutyutyityju", 
     "address3": "fdfdddffr", 
     "wPin": null, 
     "randomNumber": null 
    }, { 
     "beneficiary_serial_no": 0, 
     "beneficiary_id": "2113", 
     "senderMobileNo": null, 
     "beneficiaryName": "Girija", 
     "beneficiaryNickName": "Girija", 
     "beneficiaryType": "WalletCustomer", 
     "beneficiaryMobileNo": "9861032490", 
     "status": "Active", 
     "time": null, 
     "accountno": null, 
     "ifsccode": null, 
     "bankType": null, 
     "bankName": null, 
     "address1": "fdgfrhrgrbhegfbsdgb", 
     "address2": null, 
     "address3": null, 
     "wPin": null, 
     "randomNumber": null 
    }, { 
     "beneficiary_serial_no": 0, 
     "beneficiary_id": "2102", 
     "senderMobileNo": null, 
     "beneficiaryName": "Sonu", 
     "beneficiaryNickName": "Sonu", 
     "beneficiaryType": "OtherBankCustomer", 
     "beneficiaryMobileNo": "8093630503", 
     "status": "Active", 
     "time": null, 
     "accountno": "12365478969", 
     "ifsccode": "SBIN0000000", 
     "bankType": null, 
     "bankName": null, 
     "address1": "qwertyuiop", 
     "address2": "asdfghjkll", 
     "address3": null, 
     "wPin": null, 
     "randomNumber": null 
    }, { 
     "beneficiary_serial_no": 0, 
     "beneficiary_id": "2103", 
     "senderMobileNo": null, 
     "beneficiaryName": "kajal", 
     "beneficiaryNickName": "kajal", 
     "beneficiaryType": "OtherBankCustomer", 
     "beneficiaryMobileNo": "8093630503", 
     "status": "Active", 
     "time": null, 
     "accountno": "12365477777", 
     "ifsccode": "SBIN0000000", 
     "bankType": null, 
     "bankName": null, 
     "address1": "qwertyuiop", 
     "address2": "asdfghjkll", 
     "address3": null, 
     "wPin": null, 
     "randomNumber": null 
    }, { 
     "beneficiary_serial_no": 0, 
     "beneficiary_id": "2104", 
     "senderMobileNo": null, 
     "beneficiaryName": "Ajay", 
     "beneficiaryNickName": "Ajay", 
     "beneficiaryType": "OtherBankCustomer", 
     "beneficiaryMobileNo": "8093630503", 
     "status": "Active", 
     "time": null, 
     "accountno": "12365477775", 
     "ifsccode": "SBIN0000000", 
     "bankType": null, 
     "bankName": null, 
     "address1": "qwertyuiop", 
     "address2": "asdfghjkll", 
     "address3": null, 
     "wPin": null, 
     "randomNumber": null 
    }, { 
     "beneficiary_serial_no": 0, 
     "beneficiary_id": "2111", 
     "senderMobileNo": null, 
     "beneficiaryName": "devgan", 
     "beneficiaryNickName": "devgan", 
     "beneficiaryType": "OtherBankCustomer", 
     "beneficiaryMobileNo": "8093630503", 
     "status": "Active", 
     "time": null, 
     "accountno": "123456789012", 
     "ifsccode": "BKDN0999848", 
     "bankType": null, 
     "bankName": null, 
     "address1": "qwertyuiop", 
     "address2": "asdfghjkll", 
     "address3": null, 
     "wPin": null, 
     "randomNumber": null 
    }, { 
     "beneficiary_serial_no": 0, 
     "beneficiary_id": "2112", 
     "senderMobileNo": null, 
     "beneficiaryName": "Sony", 
     "beneficiaryNickName": "Sony", 
     "beneficiaryType": "DenaAccountCustomer", 
     "beneficiaryMobileNo": "8093630503", 
     "status": "Active", 
     "time": null, 
     "accountno": "005013023756", 
     "ifsccode": null, 
     "bankType": null, 
     "bankName": null, 
     "address1": "Near Sai temple", 
     "address2": "SBI ATM", 
     "address3": "SS bihar", 
     "wPin": null, 
     "randomNumber": null 
    }], 
    "busPasswordPolicyBean": { 
     "minLen": 1, 
     "maxLen": 2, 
     "minNumRqd": 1, 
     "minUpperCaseChars": 0, 
     "minLowerCaseChars": 0, 
     "minSpclChars": 0, 
     "spclCharSet": "#@", 
     "pwdType": "SecretCode", 
     "lastUpdatedOn": 1497433024653, 
     "updatedBy": "1234" 
    } 

} 

使用下面的JSON路径表达式:

$..[?(@.beneficiaryType == 'OtherBankCustomer')].beneficiary_id 

演示:

JMeter Conditional JSONPATh

参考文献:

+0

非常感谢..如果我想要通过这四个输出中的任何一个..将有什么表达? –

+0

您可以使用[__V()](https://jmeter.apache.org/usermanual/functions.html#__V)和[__Random()](https://jmeter.apache.org/usermanual/functions.html #__Random)功能。假设你在'JSON Extractor'中使用'id'作为“引用名称”,相关的表达式就像是:'$ {__ V(id _ $ {__ Random(1,$ {id_matchNr},)})}'。有关更多详细信息,请参见[Apache JMeter函数 - 简介](https://www.blazemeter.com/blog/apache-jmeter-functions-introduction)。 –

+0

实际上,我在beanshell预处理器中使用“id”的值作为方法的输入。我如何使用不同的“ID”值?例如,字符串strId = vars.get(“id”)。 –

的beneficiary_ids您可以添加正则表达式提取

Regular Expression: beneficiary_id": "(\d+) 
Template $1$ 
Match No. -1 
Reference Name: b 

你将得到一个存储了所有的值以下:

b_1_g1 = 2090 ... b_6_g1 = 2111 b_7_g1 = 2112

+0

我需要beneficiaryType = OtherBankCustomer仅 –

您所需的JSON路径表达式会是这样的:

$.busBeneficiaryBeanList[?(@.beneficiaryType=='OtherBankCustomer')].beneficiary_id 

enter image description here

+0

的受益者IDS我需要beneficiaryType = “OtherBankCustomer” 的受益者IDS只 –

+0

'$ .busBeneficiaryBeanList [? (@ .beneficiaryType =='OtherBankCustomer')]。beneficiary_id' – Jahan