1

I have the following JSON:

[{"hashcode": 4830991188237466859},{...}]

I have the following Angular/JS code:

var res = $resource('<something>');
...
res.query({}, function(json) {hashcode = json[0].hashcode;};
...

Surprisingly (to me, I'm no JS expert), I find that something (?) is rounding the value to the precision of 1000 (rounding the last 3 digits). This is a problem, since this is a hash code of something.

If, on the other hand I write the value as a String to the JSON, e.g -

[{"hashcode": "4830991188237466859"},{...}]

this does not happen. But this causes a different problem for me (with JMeter/JSON Path, which extracts the value ["4830991188237466859"] by running my query $.hashcode - which I can't use as a HTTP request parameter (I need to add ?hashcode=... to the query, but I end up with ?hashcode=["..."]

So I appreciate help with:

  1. Understanding who and why -- is rounding my hash, and how to avoid it
  2. Help with JMeter/JSON Path

Thanks!

sabithpocker
  • 15,274
  • 1
  • 42
  • 75
JRun
  • 3,328
  • 6
  • 27
  • 41

3 Answers3

2
  1. Each system architecture has a maximum number it can represent. See Number.MAX_VALUE or paste your number into the console. You'll see it happens at the JavaScript level, nothing to do with angular. Since the hash doesn't represent the amount of something, it's perfectly natural for it to be a string. Which leads me to

  2. Nothing wrong with site.com/page?hashcode=4830991188237466859 - it's treated as a string there and you should keep treating it as such.

Shomz
  • 37,421
  • 4
  • 57
  • 85
2

The javascript Number type is floating point based, and can only represent all integers in the range between -253 and 253. Some integers outside this range are therefore subject to "rounding" as you experience.

Jonas Høgh
  • 10,358
  • 1
  • 26
  • 46
1

In regards to JMeter JSON Path Extractor plugin, the correct JSON Path query for your hashcode will look like

$..hashcode[0]

See Parsing JSON chapter of the guide for XPath to JSON Path mappings and more details.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Dude, you rock. I think I tried all the permutations, why hasn't this come to mind ?! :-) – JRun Mar 11 '14 at 14:43