Jmeter : How to extract first element from json array

Sachetan

I am trying to extract first element from a json array. Below mentioned is json array

   [
    {
        "cohortDefinition": {
            "Key": 1151,
            "id": 1798,
            "srcId": "3526",
            "pcKey": -1,
            "userName": "CHROME_USER",
            "name": "JMeter2017-01-06-1483749546167",
            "Type": "SUBJECT",
            "tool": "CB",
            "count": 32757,
            "extractionStatus": "",
            "dateCreated": "2017-05-10T17:48:45Z"
        },
        "datasource": {
            "id": 2,
            "name": "health",
            "subjectCount": 116352
        },
        "project": {
            "id": 747,
            "name": "Jmeter Project"
        }
    },
    {
        "cohortDefinition": {
            "Key": 1150,
            "id": 1796,
            "srcId": "3525",
            "pcKey": -1,
            "userName": "CHROME_USER",
            "name": "JMeter2016-10-27-1477620919644",
            "Type": "SUBJECT",
            "tool": "CB",
            "count": 32757,
            "extractionStatus": "",
            "dateCreated": "2017-05-10T16:57:11Z"
        },
        "datasource": {
            "id": 2,
            "name": "health",
            "subjectCount": 116352
        },
        "project": {
            "id": 747,
            "name": "Jmeter Project"
        }
    }
]

From above json i would like to extract first value ie. srcId": "3526". I tried doing following expression in Jmeter extractor

$..cohortDefinition.srcId[1]

However it is not working. If anyone know how to do this please do let me know.

NaveenKumar Namachivayam

After JMeter 3.0, you can use JSON Extractor, see:

Before JMeter 3.0:

Please follow the below steps to retrieve srcId.

  1. Add a JSON Path Extractor to your request and configure below values.

Destination Variable Name - myVar

JSON Path Expression - $..cohortDefinition.srcId - this will extract all the srcIDs from the JSON.

Default Value - Not Found or Err

JSON Path Config

  1. Add a Debug Sampler and View Results Tree to your test plan.

  2. Save it and execute.

  3. In Debug Sampler, you can view all the srcId as shown below.

Output

You can now use myVar_1 and myVar_2 in your test plan using ${myVar_1} ${myVar_2}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to extract the first element from a : separated String in ANT

分類Dev

How to extract array from $_POST

分類Dev

How to extract a element of JSON script with BeautifulSoup

分類Dev

Qsort removes first element from array (char *)

分類Dev

How to extract the first column from a tsv file?

分類Dev

How to extract desired data from Jmeter response and to pass it as a request

分類Dev

Extract first value from array<string> in AWS Glue DynamicFrame

分類Dev

How to extract JSON value in strangely formatted array?

分類Dev

Make an array from list where first element of the array is the first element in list

分類Dev

How to extract a property from array of objects and slice it?

分類Dev

Want to get a specific Element from a json array,

分類Dev

How to extract JSON from script with Python?

分類Dev

how to hide first and last element from the three same element

分類Dev

Array first element

分類Dev

how to extract text from a html element by id and assign to a php variable?

分類Dev

how to extract string or number from bs4.element.NavigableString

分類Dev

How to extract the element from the dictionary without last item

分類Dev

How to group arrays in array by first element object key

分類Dev

How can I filter a JavaScript array by element first letter?

分類Dev

In Swift, How to check if the first element of an Array is equal to a list of values?

分類Dev

How to delete an element from an array in C#

分類Dev

How to remove an element from an array in Swift

分類Dev

How to extract array values within nested JSON data

分類Dev

How to extract the first element (as a list of string) of the n-th elements of a nested list, Python

分類Dev

Retain first matching element of array

分類Dev

How do I extract a specific object from a nested array?

分類Dev

How to extract only the image path from the array I'm getting?

分類Dev

How to extract list from list of lists when any one element match with another list's element?

分類Dev

how to parse only first array in the json object in android?

Related 関連記事

  1. 1

    How to extract the first element from a : separated String in ANT

  2. 2

    How to extract array from $_POST

  3. 3

    How to extract a element of JSON script with BeautifulSoup

  4. 4

    Qsort removes first element from array (char *)

  5. 5

    How to extract the first column from a tsv file?

  6. 6

    How to extract desired data from Jmeter response and to pass it as a request

  7. 7

    Extract first value from array<string> in AWS Glue DynamicFrame

  8. 8

    How to extract JSON value in strangely formatted array?

  9. 9

    Make an array from list where first element of the array is the first element in list

  10. 10

    How to extract a property from array of objects and slice it?

  11. 11

    Want to get a specific Element from a json array,

  12. 12

    How to extract JSON from script with Python?

  13. 13

    how to hide first and last element from the three same element

  14. 14

    Array first element

  15. 15

    how to extract text from a html element by id and assign to a php variable?

  16. 16

    how to extract string or number from bs4.element.NavigableString

  17. 17

    How to extract the element from the dictionary without last item

  18. 18

    How to group arrays in array by first element object key

  19. 19

    How can I filter a JavaScript array by element first letter?

  20. 20

    In Swift, How to check if the first element of an Array is equal to a list of values?

  21. 21

    How to delete an element from an array in C#

  22. 22

    How to remove an element from an array in Swift

  23. 23

    How to extract array values within nested JSON data

  24. 24

    How to extract the first element (as a list of string) of the n-th elements of a nested list, Python

  25. 25

    Retain first matching element of array

  26. 26

    How do I extract a specific object from a nested array?

  27. 27

    How to extract only the image path from the array I'm getting?

  28. 28

    How to extract list from list of lists when any one element match with another list's element?

  29. 29

    how to parse only first array in the json object in android?

ホットタグ

アーカイブ