Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Compare a set of elements of the JSON response to the standard set of elements

Baahubali
Baahubali Posts: 14

I have a JSON reponse with 152 currency codes fields. I need to compare the whole set of currency codes in the response with the standard set of codes. The issue is the currency codes in the JSON response are dynamic and they do not have a order, if they would have I would have added a string comparison and mapped to my standard set of codes. What can I do here?

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,119 ✭✭✭
    edited June 2017

    I recommend using the Diff tool for your validation. Field order in JSON objects doesn't matter in the sense that it doesn't affect the semantics of the message. For this reason, the Diff tool's JSON mode will ignore the order of fields within objects. However, if you need to ignore order of an array of JSON objects, as opposed to order of fields within a JSON object, then you would likely need should sort the objects prior to diffing. One way to do this would be to convert the JSON to XML using the XML Converter then use the Diff tool's XML mode which has an option to ignore element order. There is also an XML Sort tool if you wanted to sort the XML then wanted to convert it back to JSON afterwards, for example.

  • Baahubali
    Baahubali Posts: 14
    edited June 2017

    I unable to reproduce the method you described.
    I have this list of currencies to validate if they are present in the JSON response.
    AED
    ALL
    AMD
    ANG
    AOA
    ARS
    AUD
    AWG
    AZN
    BAM
    BBD
    BDT
    BGN
    BHD
    BIF
    BMD
    BND
    BOB
    BRL
    BSD
    BWP
    BYR
    BZD
    CDF
    CHF
    CLP
    CNY
    COP
    CRC
    CUP
    CVE
    CZK
    DJF
    DKK
    DOP
    DZD
    EGP
    ERN
    ETB
    EUR
    FJD
    FKP
    GBP
    GEL
    GHS
    GIP
    GMD
    GNF
    GTQ
    GYD
    HKD
    HNL
    HRK
    HTG
    HUF
    IDR
    ILS
    INR
    IQD
    IRR
    ISK
    JMD
    JOD
    JPY
    KES
    KGS
    KHR
    KMF
    KPW
    KRW
    KWD
    KYD
    KZT
    LAK
    LBP
    LKR
    LRD
    LSL
    LTL
    LYD
    MAD
    MDL
    MGA
    MKD
    MMK
    MNT
    MOP
    MRO
    MUR
    MVR
    MWK
    MXN
    MYR
    MZN
    NAD
    NGN
    NIO
    NOK
    NPR
    NZD
    OMR
    PAB
    PEN
    PGK
    PHP
    PKR
    PLN
    PYG
    QAR
    RON
    RSD
    RUB
    RWF
    SAR
    SBD
    SCR
    SDD
    SEK
    SGD
    SHP
    SLL
    SOS
    SRD
    STD
    SYP
    SZL
    THB
    TJS
    TMT
    TND
    TOP
    TRY
    TTD
    TWD
    TZS
    UAH
    UGX
    USD
    UYU
    UZS
    VEF
    VND
    VUV
    WST
    XAF
    XCD
    XOF
    XPF
    YER
    ZAR
    ZMW
    ZWL

    Compare the above list of codes with the below
    {
        "foreignExchageRates": [{
                "sourceCurrencyCode": "STD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.00005125,
                "rateRetrievalDate": "2017-06-29T12:57:07+0000"
            },
            {
                "sourceCurrencyCode": "BOB",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.146998325,
                "rateRetrievalDate": "2017-06-29T12:56:45+0000"
            },
            {
                "sourceCurrencyCode": "UAH",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.125106375,
                "rateRetrievalDate": "2017-06-29T12:57:10+0000"
            },
            {
                "sourceCurrencyCode": "CLP",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.002127900,
                "rateRetrievalDate": "2017-06-29T12:56:47+0000"
            },
            {
                "sourceCurrencyCode": "FKP",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.642346225,
                "rateRetrievalDate": "2017-06-29T12:56:50+0000"
            },
            {
                "sourceCurrencyCode": "NOK",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.177890800,
                "rateRetrievalDate": "2017-06-29T12:57:02+0000"
            },
            {
                "sourceCurrencyCode": "GMD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.029563050,
                "rateRetrievalDate": "2017-06-29T12:56:51+0000"
            },
            {
                "sourceCurrencyCode": "VND",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.000049200,
                "rateRetrievalDate": "2017-06-29T12:57:11+0000"
            },
            {
                "sourceCurrencyCode": "TOP",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.591981575,
                "rateRetrievalDate": "2017-06-29T12:57:09+0000"
            },
            {
                "sourceCurrencyCode": "SGD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.836364125,
                "rateRetrievalDate": "2017-06-29T12:57:06+0000"
            },
            {
                "sourceCurrencyCode": "BBD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.514032375,
                "rateRetrievalDate": "2017-06-29T12:56:44+0000"
            },
            {
                "sourceCurrencyCode": "AED",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.278548875,
                "rateRetrievalDate": "2017-06-29T12:56:41+0000"
            },
            {
                "sourceCurrencyCode": "AMD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.002557375,
                "rateRetrievalDate": "2017-06-29T12:56:42+0000"
            },
            {
                "sourceCurrencyCode": "ILS",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.262591675,
                "rateRetrievalDate": "2017-06-29T12:56:54+0000"
            },
            {
                "sourceCurrencyCode": "CZK",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.053090900,
                "rateRetrievalDate": "2017-06-29T12:56:48+0000"
            },
            {
                "sourceCurrencyCode": "DOP",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.026085225,
                "rateRetrievalDate": "2017-06-29T12:56:49+0000"
            },
            {
                "sourceCurrencyCode": "ZMW",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.025,
                "rateRetrievalDate": "2017-06-29T12:57:13+0000"
            },
            {
                "sourceCurrencyCode": "JMD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.011354950,
                "rateRetrievalDate": "2017-06-29T12:56:55+0000"
            },
            {
                "sourceCurrencyCode": "MAD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.120094125,
                "rateRetrievalDate": "2017-06-29T12:56:58+0000"
            },
            {
                "sourceCurrencyCode": "JOD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.440825075,
                "rateRetrievalDate": "2017-06-29T12:56:55+0000"
            },
            {
                "sourceCurrencyCode": "SYP",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.014730275,
                "rateRetrievalDate": "2017-06-29T12:57:07+0000"
            },
            {
                "sourceCurrencyCode": "MRO",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.003477825,
                "rateRetrievalDate": "2017-06-29T12:57:00+0000"
            },
            {
                "sourceCurrencyCode": "BND",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.836364125,
                "rateRetrievalDate": "2017-06-29T12:56:45+0000"
            },
            {
                "sourceCurrencyCode": "ISK",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.01022950,
                "rateRetrievalDate": "2017-06-29T12:56:54+0000"
            },
            {
                "sourceCurrencyCode": "LBP",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.000685725,
                "rateRetrievalDate": "2017-06-29T12:56:57+0000"
            },
            {
                "sourceCurrencyCode": "TMT",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.359771925,
                "rateRetrievalDate": "2017-06-29T12:57:08+0000"
            },
            {
                "sourceCurrencyCode": "AOA",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.010638475,
                "rateRetrievalDate": "2017-06-29T12:56:42+0000"
            },
            {
                "sourceCurrencyCode": "SDD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.025,
                "rateRetrievalDate": "2017-06-29T12:57:06+0000"
            },
            {
                "sourceCurrencyCode": "HTG",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.024141825,
                "rateRetrievalDate": "2017-06-29T12:56:53+0000"
            },
            {
                "sourceCurrencyCode": "SHP",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.642346225,
                "rateRetrievalDate": "2017-06-29T12:57:07+0000"
            },
            {
                "sourceCurrencyCode": "SBD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.13820075,
                "rateRetrievalDate": "2017-06-29T12:57:05+0000"
            },
            {
                "sourceCurrencyCode": "FJD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.569476675,
                "rateRetrievalDate": "2017-06-29T12:56:50+0000"
            },
            {
                "sourceCurrencyCode": "EGP",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.167457325,
                "rateRetrievalDate": "2017-06-29T12:56:49+0000"
            },
            {
                "sourceCurrencyCode": "ARS",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.214410525,
                "rateRetrievalDate": "2017-06-29T12:56:43+0000"
            },
            {
                "sourceCurrencyCode": "NIO",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.042758900,
                "rateRetrievalDate": "2017-06-29T12:57:01+0000"
            },
            {
                "sourceCurrencyCode": "MOP",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.12786875,
                "rateRetrievalDate": "2017-06-29T12:56:59+0000"
            },
            {
                "sourceCurrencyCode": "AWG",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.571522575,
                "rateRetrievalDate": "2017-06-29T12:56:43+0000"
            },
            {
                "sourceCurrencyCode": "MGA",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.025,
                "rateRetrievalDate": "2017-06-29T12:56:59+0000"
            },
            {
                "sourceCurrencyCode": "TTD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.160603150,
                "rateRetrievalDate": "2017-06-29T12:57:09+0000"
            },
            {
                "sourceCurrencyCode": "TRY",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.56783975,
                "rateRetrievalDate": "2017-06-29T12:57:09+0000"
            },
            {
                "sourceCurrencyCode": "CRC",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.002045900,
                "rateRetrievalDate": "2017-06-29T12:56:47+0000"
            },
            {
                "sourceCurrencyCode": "PHP",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.024755800,
                "rateRetrievalDate": "2017-06-29T12:57:03+0000"
            },
            {
                "sourceCurrencyCode": "GTQ",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.130528625,
                "rateRetrievalDate": "2017-06-29T12:56:52+0000"
            },
            {
                "sourceCurrencyCode": "XOF",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.002045900,
                "rateRetrievalDate": "2017-06-29T12:57:12+0000"
            },
            {
                "sourceCurrencyCode": "RUB",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.032529400,
                "rateRetrievalDate": "2017-06-29T12:57:05+0000"
            },
            {
                "sourceCurrencyCode": "KHR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.0002050,
                "rateRetrievalDate": "2017-06-29T12:56:56+0000"
            },
            {
                "sourceCurrencyCode": "BGN",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.678829825,
                "rateRetrievalDate": "2017-06-29T12:56:44+0000"
            },
            {
                "sourceCurrencyCode": "BDT",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.012480400,
                "rateRetrievalDate": "2017-06-29T12:56:44+0000"
            },
            {
                "sourceCurrencyCode": "NPR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.011763925,
                "rateRetrievalDate": "2017-06-29T12:57:02+0000"
            },
            {
                "sourceCurrencyCode": "QAR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.281004775,
                "rateRetrievalDate": "2017-06-29T12:57:04+0000"
            },
            {
                "sourceCurrencyCode": "TJS",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.21492200,
                "rateRetrievalDate": "2017-06-29T12:57:08+0000"
            },
            {
                "sourceCurrencyCode": "MYR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.335016125,
                "rateRetrievalDate": "2017-06-29T12:57:01+0000"
            },
            {
                "sourceCurrencyCode": "HUF",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.004705775,
                "rateRetrievalDate": "2017-06-29T12:56:53+0000"
            },
            {
                "sourceCurrencyCode": "MMK",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.001207450,
                "rateRetrievalDate": "2017-06-29T12:56:59+0000"
            },
            {
                "sourceCurrencyCode": "BYR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.0001025,
                "rateRetrievalDate": "2017-06-29T12:56:46+0000"
            },
            {
                "sourceCurrencyCode": "IDR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.0001025,
                "rateRetrievalDate": "2017-06-29T12:56:53+0000"
            },
            {
                "sourceCurrencyCode": "BRL",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.503393900,
                "rateRetrievalDate": "2017-06-29T12:56:45+0000"
            },
            {
                "sourceCurrencyCode": "MDL",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.083472925,
                "rateRetrievalDate": "2017-06-29T12:56:59+0000"
            },
            {
                "sourceCurrencyCode": "SAR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.272821175,
                "rateRetrievalDate": "2017-06-29T12:57:05+0000"
            },
            {
                "sourceCurrencyCode": "HNL",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.051965450,
                "rateRetrievalDate": "2017-06-29T12:56:52+0000"
            },
            {
                "sourceCurrencyCode": "VEF",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.237938375,
                "rateRetrievalDate": "2017-06-29T12:57:11+0000"
            },
            {
                "sourceCurrencyCode": "LTL",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.384526700,
                "rateRetrievalDate": "2017-06-29T12:56:58+0000"
            },
            {
                "sourceCurrencyCode": "AZN",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.025,
                "rateRetrievalDate": "2017-06-29T12:56:43+0000"
            },
            {
                "sourceCurrencyCode": "COP",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.000511475,
                "rateRetrievalDate": "2017-06-29T12:56:47+0000"
            },
            {
                "sourceCurrencyCode": "PYG",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.0002050,
                "rateRetrievalDate": "2017-06-29T12:57:04+0000"
            },
            {
                "sourceCurrencyCode": "ANG",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.571522575,
                "rateRetrievalDate": "2017-06-29T12:56:42+0000"
            },
            {
                "sourceCurrencyCode": "XPF",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.011047450,
                "rateRetrievalDate": "2017-06-29T12:57:12+0000"
            },
            {
                "sourceCurrencyCode": "NZD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.836261625,
                "rateRetrievalDate": "2017-06-29T12:57:02+0000"
            },
            {
                "sourceCurrencyCode": "DKK",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.177481825,
                "rateRetrievalDate": "2017-06-29T12:56:48+0000"
            },
            {
                "sourceCurrencyCode": "MNT",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.000716475,
                "rateRetrievalDate": "2017-06-29T12:56:59+0000"
            },
            {
                "sourceCurrencyCode": "PKR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.010638475,
                "rateRetrievalDate": "2017-06-29T12:57:03+0000"
            },
            {
                "sourceCurrencyCode": "SLL",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.00023575,
                "rateRetrievalDate": "2017-06-29T12:57:07+0000"
            },
            {
                "sourceCurrencyCode": "SEK",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.1536475,
                "rateRetrievalDate": "2017-06-29T12:57:06+0000"
            },
            {
                "sourceCurrencyCode": "RSD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.011661425,
                "rateRetrievalDate": "2017-06-29T12:57:04+0000"
            },
            {
                "sourceCurrencyCode": "WST",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.446006200,
                "rateRetrievalDate": "2017-06-29T12:57:11+0000"
            },
            {
                "sourceCurrencyCode": "HKD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.131960550,
                "rateRetrievalDate": "2017-06-29T12:56:52+0000"
            },
            {
                "sourceCurrencyCode": "KWD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 3.635052825,
                "rateRetrievalDate": "2017-06-29T12:56:56+0000"
            },
            {
                "sourceCurrencyCode": "CDF",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.001125450,
                "rateRetrievalDate": "2017-06-29T12:56:46+0000"
            },
            {
                "sourceCurrencyCode": "BAM",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.677090400,
                "rateRetrievalDate": "2017-06-29T12:56:44+0000"
            },
            {
                "sourceCurrencyCode": "GIP",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.642346225,
                "rateRetrievalDate": "2017-06-29T12:56:51+0000"
            },
            {
                "sourceCurrencyCode": "XCD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.380537400,
                "rateRetrievalDate": "2017-06-29T12:57:12+0000"
            },
            {
                "sourceCurrencyCode": "JPY",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.012786875,
                "rateRetrievalDate": "2017-06-29T12:56:55+0000"
            },
            {
                "sourceCurrencyCode": "KRW",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.000920450,
                "rateRetrievalDate": "2017-06-29T12:56:56+0000"
            },
            {
                "sourceCurrencyCode": "CHF",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.095579450,
                "rateRetrievalDate": "2017-06-29T12:56:47+0000"
            },
            {
                "sourceCurrencyCode": "TND",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.650289725,
                "rateRetrievalDate": "2017-06-29T12:57:08+0000"
            },
            {
                "sourceCurrencyCode": "OMR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 2.656703650,
                "rateRetrievalDate": "2017-06-29T12:57:02+0000"
            },
            {
                "sourceCurrencyCode": "YER",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.004757025,
                "rateRetrievalDate": "2017-06-29T12:57:12+0000"
            },
            {
                "sourceCurrencyCode": "VUV",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.010535975,
                "rateRetrievalDate": "2017-06-29T12:57:11+0000"
            },
            {
                "sourceCurrencyCode": "MZN",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.035086775,
                "rateRetrievalDate": "2017-06-29T12:57:01+0000"
            },
            {
                "sourceCurrencyCode": "ETB",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.05615975,
                "rateRetrievalDate": "2017-06-29T12:56:50+0000"
            },
            {
                "sourceCurrencyCode": "LRD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.014423800,
                "rateRetrievalDate": "2017-06-29T12:56:58+0000"
            },
            {
                "sourceCurrencyCode": "MUR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.032836900,
                "rateRetrievalDate": "2017-06-29T12:57:00+0000"
            },
            {
                "sourceCurrencyCode": "MXN",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.0784125,
                "rateRetrievalDate": "2017-06-29T12:57:00+0000"
            },
            {
                "sourceCurrencyCode": "NGN",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.006546675,
                "rateRetrievalDate": "2017-06-29T12:57:01+0000"
            },
            {
                "sourceCurrencyCode": "TZS",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.000613975,
                "rateRetrievalDate": "2017-06-29T12:57:10+0000"
            },
            {
                "sourceCurrencyCode": "SRD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.305350575,
                "rateRetrievalDate": "2017-06-29T12:57:07+0000"
            },
            {
                "sourceCurrencyCode": "NAD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.117127775,
                "rateRetrievalDate": "2017-06-29T12:57:01+0000"
            },
            {
                "sourceCurrencyCode": "PAB",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.022950,
                "rateRetrievalDate": "2017-06-29T12:57:03+0000"
            },
            {
                "sourceCurrencyCode": "CVE",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.01022950,
                "rateRetrievalDate": "2017-06-29T12:56:48+0000"
            },
            {
                "sourceCurrencyCode": "RWF",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.022950,
                "rateRetrievalDate": "2017-06-29T12:57:05+0000"
            },
            {
                "sourceCurrencyCode": "CNY",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.16377450,
                "rateRetrievalDate": "2017-06-29T12:56:47+0000"
            },
            {
                "sourceCurrencyCode": "ZWL",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.025,
                "rateRetrievalDate": "2017-06-29T12:57:13+0000"
            },
            {
                "sourceCurrencyCode": "IQD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.000920450,
                "rateRetrievalDate": "2017-06-29T12:56:54+0000"
            },
            {
                "sourceCurrencyCode": "HRK",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.176458875,
                "rateRetrievalDate": "2017-06-29T12:56:53+0000"
            },
            {
                "sourceCurrencyCode": "KES",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.011968925,
                "rateRetrievalDate": "2017-06-29T12:56:55+0000"
            },
            {
                "sourceCurrencyCode": "LYD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.822349300,
                "rateRetrievalDate": "2017-06-29T12:56:58+0000"
            },
            {
                "sourceCurrencyCode": "EUR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.3245050,
                "rateRetrievalDate": "2017-06-29T12:56:50+0000"
            },
            {
                "sourceCurrencyCode": "ZAR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.117127775,
                "rateRetrievalDate": "2017-06-29T12:57:13+0000"
            },
            {
                "sourceCurrencyCode": "DZD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.012889375,
                "rateRetrievalDate": "2017-06-29T12:56:49+0000"
            },
            {
                "sourceCurrencyCode": "SCR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.079995100,
                "rateRetrievalDate": "2017-06-29T12:57:06+0000"
            },
            {
                "sourceCurrencyCode": "ERN",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.068231175,
                "rateRetrievalDate": "2017-06-29T12:56:49+0000"
            },
            {
                "sourceCurrencyCode": "CUP",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.022950,
                "rateRetrievalDate": "2017-06-29T12:56:48+0000"
            },
            {
                "sourceCurrencyCode": "BIF",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.000716475,
                "rateRetrievalDate": "2017-06-29T12:56:45+0000"
            },
            {
                "sourceCurrencyCode": "GEL",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.616020900,
                "rateRetrievalDate": "2017-06-29T12:56:51+0000"
            },
            {
                "sourceCurrencyCode": "BHD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 2.713068400,
                "rateRetrievalDate": "2017-06-29T12:56:44+0000"
            },
            {
                "sourceCurrencyCode": "GBP",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.6429725,
                "rateRetrievalDate": "2017-06-29T12:56:51+0000"
            },
            {
                "sourceCurrencyCode": "TWD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.034985300,
                "rateRetrievalDate": "2017-06-29T12:57:09+0000"
            },
            {
                "sourceCurrencyCode": "THB",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.025,
                "rateRetrievalDate": "2017-06-29T12:57:08+0000"
            },
            {
                "sourceCurrencyCode": "XAF",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.002045900,
                "rateRetrievalDate": "2017-06-29T12:57:12+0000"
            },
            {
                "sourceCurrencyCode": "UZS",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.000511475,
                "rateRetrievalDate": "2017-06-29T12:57:11+0000"
            },
            {
                "sourceCurrencyCode": "KYD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.2275400,
                "rateRetrievalDate": "2017-06-29T12:56:57+0000"
            },
            {
                "sourceCurrencyCode": "MVR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.065263800,
                "rateRetrievalDate": "2017-06-29T12:57:00+0000"
            },
            {
                "sourceCurrencyCode": "MWK",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.003273850,
                "rateRetrievalDate": "2017-06-29T12:57:00+0000"
            },
            {
                "sourceCurrencyCode": "KMF",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.002659875,
                "rateRetrievalDate": "2017-06-29T12:56:56+0000"
            },
            {
                "sourceCurrencyCode": "KZT",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.006751675,
                "rateRetrievalDate": "2017-06-29T12:56:57+0000"
            },
            {
                "sourceCurrencyCode": "LSL",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.117127775,
                "rateRetrievalDate": "2017-06-29T12:56:58+0000"
            },
            {
                "sourceCurrencyCode": "INR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.018822075,
                "rateRetrievalDate": "2017-06-29T12:56:54+0000"
            },
            {
                "sourceCurrencyCode": "AUD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.0582100,
                "rateRetrievalDate": "2017-06-29T12:56:43+0000"
            },
            {
                "sourceCurrencyCode": "KGS",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.021686950,
                "rateRetrievalDate": "2017-06-29T12:56:55+0000"
            },
            {
                "sourceCurrencyCode": "SZL",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.117127775,
                "rateRetrievalDate": "2017-06-29T12:57:08+0000"
            },
            {
                "sourceCurrencyCode": "BWP",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.130119650,
                "rateRetrievalDate": "2017-06-29T12:56:46+0000"
            },
            {
                "sourceCurrencyCode": "BZD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.515975775,
                "rateRetrievalDate": "2017-06-29T12:56:46+0000"
            },
            {
                "sourceCurrencyCode": "GYD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.00501225,
                "rateRetrievalDate": "2017-06-29T12:56:52+0000"
            },
            {
                "sourceCurrencyCode": "IRR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.00008200,
                "rateRetrievalDate": "2017-06-29T12:56:54+0000"
            },
            {
                "sourceCurrencyCode": "GNF",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.0001025,
                "rateRetrievalDate": "2017-06-29T12:56:51+0000"
            },
            {
                "sourceCurrencyCode": "DJF",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.025,
                "rateRetrievalDate": "2017-06-29T12:56:48+0000"
            },
            {
                "sourceCurrencyCode": "LKR",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.007877125,
                "rateRetrievalDate": "2017-06-29T12:56:57+0000"
            },
            {
                "sourceCurrencyCode": "BMD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.022950,
                "rateRetrievalDate": "2017-06-29T12:56:45+0000"
            },
            {
                "sourceCurrencyCode": "PEN",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.395575175,
                "rateRetrievalDate": "2017-06-29T12:57:03+0000"
            },
            {
                "sourceCurrencyCode": "UGX",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.000398725,
                "rateRetrievalDate": "2017-06-29T12:57:10+0000"
            },
            {
                "sourceCurrencyCode": "LAK",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.00012300,
                "rateRetrievalDate": "2017-06-29T12:56:57+0000"
            },
            {
                "sourceCurrencyCode": "PGK",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.479558550,
                "rateRetrievalDate": "2017-06-29T12:57:03+0000"
            },
            {
                "sourceCurrencyCode": "SOS",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.000613975,
                "rateRetrievalDate": "2017-06-29T12:57:07+0000"
            },
            {
                "sourceCurrencyCode": "BSD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.022950,
                "rateRetrievalDate": "2017-06-29T12:56:46+0000"
            },
            {
                "sourceCurrencyCode": "UYU",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.0513525,
                "rateRetrievalDate": "2017-06-29T12:57:11+0000"
            },
            {
                "sourceCurrencyCode": "ALL",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.009513025,
                "rateRetrievalDate": "2017-06-29T12:56:42+0000"
            },
            {
                "sourceCurrencyCode": "MKD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.021584450,
                "rateRetrievalDate": "2017-06-29T12:56:59+0000"
            },
            {
                "sourceCurrencyCode": "KPW",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.4603275,
                "rateRetrievalDate": "2017-06-29T12:56:56+0000"
            },
            {
                "sourceCurrencyCode": "USD",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 1.022950,
                "rateRetrievalDate": "2017-06-29T12:57:10+0000"
            },
            {
                "sourceCurrencyCode": "GHS",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.545538825,
                "rateRetrievalDate": "2017-06-29T12:56:51+0000"
            },
            {
                "sourceCurrencyCode": "RON",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.292563700,
                "rateRetrievalDate": "2017-06-29T12:57:04+0000"
            },
            {
                "sourceCurrencyCode": "PLN",
                "destinationCurrencyCode": "CAD",
                "conversionRate": 0.320388350,
                "rateRetrievalDate": "2017-06-29T12:57:04+0000"
            }
        ]
    }
    
  • OmarR
    OmarR Posts: 231 admin

    Baahubali,

    What particular section of @benken_parasoft 's method are you having difficulty with? It would be very helpful to see your current progress to understand how we can help. :)

  • grigorb
    grigorb Posts: 17

    For just validating one currency if it exists in response or not you can add JSON Assertor to response and add "Value Occurrence Assertion" in selected element specifying this regular expression "/root/foreignExchageRates/item/(sourceCurrencyCode|destinationCurrencyCode)/text()" assuming the JSON structure is not changing.
    For verifying all currencies maybe add table data source with all currencies and parameterize the value in JOSN Assertor.

  • grigorb
    grigorb Posts: 17

    One better solution is to use Custom Assertion with above specified xpath as Selected Element.
    Something like this
    boolean checkCurrency(String input, Context context) {
    String[] currencies = {"AED", "ALL", "AMD"... "ZWL"};
    for(String currency: currencies) {
    if (!input.contains(currency)) {
    return false;
    }
    }
    return true;
    }

  • Baahubali
    Baahubali Posts: 14

    My requirement is to check the occurenceof sourceCurrencyCode element in the JSON with a set of standard list of sourceCurrencyCode which I have on a excel sheet.
    There are 152 sourceCurrencyCode's expected in the JSON which is to be compared or asserted against the standard list in the excel sheet

  • venkata
    venkata Posts: 6

    from com.parasoft.api import *
    from soaptest.api import *
    import java.util.ArrayList as ArrayList
    def Test(input, context): # Defining a function with input,context parameters
    list = ArrayList() #Defining a ArrayList
    list = context.getValues("BaahubaliDataSourceName","BaahubaliColumnName") # Getting all the values in the columns as an arrayList
    Application.showMessage(input) # Printing the value before comparing
    if list.contains(input):
    return 1
    else:
    return 0

    Hope this helps!!

  • grigorb
    grigorb Posts: 17

    One more better solution will be to add Custom Assertion with the same regular expression and specify the code something like this.
    import com.parasoft.api.*;
    boolean checkCurrency(input, context) {
    String[] currencies = [
    "AED",
    "ALL",
    "AMD",
    "ANG",
    "AOA",
    "ARS",
    "AUD",
    "AWG",
    "AZN",
    "BAM",
    "BBD",
    "BDT",
    "BGN",
    "BHD",
    "BIF",
    "BMD",
    "BND",
    "BOB",
    "BRL",
    "BSD",
    "BWP",
    "BYR",
    "BZD",
    "CDF",
    "CHF",
    "CLP",
    "CNY",
    "COP",
    "CRC",
    "CUP",
    "CVE",
    "CZK",
    "DJF",
    "DKK",
    "DOP",
    "DZD",
    "EGP",
    "ERN",
    "ETB",
    "EUR",
    "FJD",
    "FKP",
    "GBP",
    "GEL",
    "GHS",
    "GIP",
    "GMD",
    "GNF",
    "GTQ",
    "GYD",
    "HKD",
    "HNL",
    "HRK",
    "HTG",
    "HUF",
    "IDR",
    "ILS",
    "INR",
    "IQD",
    "IRR",
    "ISK",
    "JMD",
    "JOD",
    "JPY",
    "KES",
    "KGS",
    "KHR",
    "KMF",
    "KPW",
    "KRW",
    "KWD",
    "KYD",
    "KZT",
    "LAK",
    "LBP",
    "LKR",
    "LRD",
    "LSL",
    "LTL",
    "LYD",
    "MAD",
    "MDL",
    "MGA",
    "MKD",
    "MMK",
    "MNT",
    "MOP",
    "MRO",
    "MUR",
    "MVR",
    "MWK",
    "MXN",
    "MYR",
    "MZN",
    "NAD",
    "NGN",
    "NIO",
    "NOK",
    "NPR",
    "NZD",
    "OMR",
    "PAB",
    "PEN",
    "PGK",
    "PHP",
    "PKR",
    "PLN",
    "PYG",
    "QAR",
    "RON",
    "RSD",
    "RUB",
    "RWF",
    "SAR",
    "SBD",
    "SCR",
    "SDD",
    "SEK",
    "SGD",
    "SHP",
    "SLL",
    "SOS",
    "SRD",
    "STD",
    "SYP",
    "SZL",
    "THB",
    "TJS",
    "TMT",
    "TND",
    "TOP",
    "TRY",
    "TTD",
    "TWD",
    "TZS",
    "UAH",
    "UGX",
    "USD",
    "UYU",
    "UZS",
    "VEF",
    "VND",
    "VUV",
    "WST",
    "XAF",
    "XCD",
    "XOF",
    "XPF",
    "YER",
    "ZAR",
    "ZMW",
    "ZWL" ];

    if (!currencies.contains(input)) {
        return false;
    }
    return true;
    

    }

  • grigorb
    grigorb Posts: 17

    One better solution is to use Custom Assertion with above specified xpath as Selected Element.
    Something like this
    import com.parasoft.api.*;
    boolean checkCurrency(input, context) {
    String[] currencies = [
    "AED",
    "ALL",
    "AMD",
    "ANG",
    "AOA",
    "ARS",
    "AUD",
    "AWG",
    "AZN",
    "BAM",
    "BBD",
    "BDT",
    "BGN",
    "BHD",
    "BIF",
    "BMD",
    "BND",
    "BOB",
    "BRL",
    "BSD",
    "BWP",
    "BYR",
    "BZD",
    "CDF",
    "CHF",
    "CLP",
    "CNY",
    "COP",
    "CRC",
    "CUP",
    "CVE",
    "CZK",
    "DJF",
    "DKK",
    "DOP",
    "DZD",
    "EGP",
    "ERN",
    "ETB",
    "EUR",
    "FJD",
    "FKP",
    "GBP",
    "GEL",
    "GHS",
    "GIP",
    "GMD",
    "GNF",
    "GTQ",
    "GYD",
    "HKD",
    "HNL",
    "HRK",
    "HTG",
    "HUF",
    "IDR",
    "ILS",
    "INR",
    "IQD",
    "IRR",
    "ISK",
    "JMD",
    "JOD",
    "JPY",
    "KES",
    "KGS",
    "KHR",
    "KMF",
    "KPW",
    "KRW",
    "KWD",
    "KYD",
    "KZT",
    "LAK",
    "LBP",
    "LKR",
    "LRD",
    "LSL",
    "LTL",
    "LYD",
    "MAD",
    "MDL",
    "MGA",
    "MKD",
    "MMK",
    "MNT",
    "MOP",
    "MRO",
    "MUR",
    "MVR",
    "MWK",
    "MXN",
    "MYR",
    "MZN",
    "NAD",
    "NGN",
    "NIO",
    "NOK",
    "NPR",
    "NZD",
    "OMR",
    "PAB",
    "PEN",
    "PGK",
    "PHP",
    "PKR",
    "PLN",
    "PYG",
    "QAR",
    "RON",
    "RSD",
    "RUB",
    "RWF",
    "SAR",
    "SBD",
    "SCR",
    "SDD",
    "SEK",
    "SGD",
    "SHP",
    "SLL",
    "SOS",
    "SRD",
    "STD",
    "SYP",
    "SZL",
    "THB",
    "TJS",
    "TMT",
    "TND",
    "TOP",
    "TRY",
    "TTD",
    "TWD",
    "TZS",
    "UAH",
    "UGX",
    "USD",
    "UYU",
    "UZS",
    "VEF",
    "VND",
    "VUV",
    "WST",
    "XAF",
    "XCD",
    "XOF",
    "XPF",
    "YER",
    "ZAR",
    "ZMW",
    "ZWL" ];

    if (!currencies.contains(input)) {
        return false;
    }
    return true;
    

    }