Forum Discussion

dumbuser's avatar
dumbuser
Occasional Contributor
7 years ago

setProprertyValue string to integer to insert into database

From REST Request I get a json response which contains an accountID which I want to use in the next teststep as and id in insertion to database.   In the REST request I use script assertion:  impo...
  • JHunt's avatar
    7 years ago

    Rao has identified the issue correctly, just got the order a little wrong.

     

    You should be able to spot the problem following this:

     

    def parse = {json -> new net.sf.json.groovy.JsonSlurper().parseText(json)}
    
    def json1 = '{"accountId":1000092192}'
    def json2 = '[{"accountId": 1000092192}]'
    
    assert parse(json1).accountId.toString() == '1000092192'
    assert parse(json2).accountId.toString() == '[1000092192]'
    
    assert parse(json2).first().toString() == json1
    assert parse(json2).first().accountId.toString() == '1000092192'

     Alternative notation:

     

    assert parse(json2)[0] == parse(json2).first()