2

In ReadyAPI I have a JSON response like:

{
    "Example" : [
       {
         "Name" : "Name_1",
         "Id" : 20100202141652076488478
      }]
}

Now, I want to get this Id using Groovy and save it to a property in ReadyAPI. The problem is that this number is too large and is changed to -6748898691334772962

Before using JsonSlurper I see that the value is correct. After JsonSlurper it changes to -6748898691334772962

What are my options to retain 20100202141652076488478?

1 Answers1

2

You can use

import grails.converters.JSON

def json = JSON.parse(yourJson)

20100202141652076488478 comes out correctly as java.math.BigInteger

Onno Rouast
  • 662
  • 5
  • 14
  • I get an " unable to resolve class grails.converters.JSON". So, now I am trying to dinf out why. – Maximus2579 Sep 03 '20 at 14:42
  • 1
    This answer requires you to have [grails](https://grails.org/) on your classpath (or be writing this as a part of a grails application). If you are in pure groovy (i.e. not in a grails project), you will not have the `JSON` class mentioned in this solution available to you. – Matias Bjarland Sep 03 '20 at 14:48