Forum Discussion

Anabelle's avatar
Anabelle
Occasional Contributor
2 years ago

Put a Json in a variable ?

Hi all,

In my keywordTest, I send au request with a json body.

 

I would like stock this json in a variable because I need to work with it ( retrieve data & modify je the json )

 

Is it possible ?

 

Thank you so much for helping

  • Here's an example,

    using JSON to construct the string and to parse

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Here's an example,

    using JSON to construct the string and to parse

  • Anabelle's avatar
    Anabelle
    Occasional Contributor

    Hello, thanks for your helping.

     

    How I can modify a value in my json ?

     

    I need to increment 'numeroPrestation' in my json each time the test has to run

     

    I try to retrieve it and put in a variable but I can't put this variable in my json

     

    Thanks in advance !

     

    Ana

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    In the example I have shown, I have an object declared as 

     

    myjson = {
      title: "SmartBear",
      body: "TestComplete",
      userid: 1
    }

     

    I can modify the value like so,

     

    myjson.body = "TestExecute"

     

    and then convert to json, as shown in the example.

     

    You have to create an object, in order to modify the values. There's plenty of examples on the internet.