Skip to content

Commit e494f29

Browse files
committed
add faq to readme
1 parent 94379e0 commit e494f29

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ Installation
3636
* http://gdata.youtube.com/feeds/api/standardfeeds/most_popular?alt=json&v=2
3737
* http://twitter.com/statuses/public_timeline.json
3838

39+
FAQ
40+
---
3941

40-
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/callumlocke/json-formatter/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
42+
### Why are large numbers not displayed accurately?
4143

44+
This is a [limitation of JavaScript](http://www.ecma-international.org/ecma-262/5.1/#sec-15.7.3.2) (and therefore JSON). The largest possible number is `Number.MAX_SAFE_INTEGER`, or **9007199254740991**. If you try to use a number larger than this in JavaScript/JSON, you'll lose accuracy.
45+
46+
The idea of JSON Formatter is to show you how the computer sees your JSON, so we don't attempt to circumvent this limitation, otherwise that would give a misleading representation of your data. It's better to see exactly what V8 sees.
47+
48+
If you want to use long sequences of digits in your JSON, then **quote them as strings**.
49+
50+
### Why are object keys sometimes in the wrong order?
51+
52+
What you see in JSON Formatter is a representation of the **parsed** object/array. You see what V8 sees.
53+
54+
Plain JavaScript objects are [unordered collections of properties](http://www.ecma-international.org/ecma-262/5.1/#sec-12.6.4). If you go through them with `for...in`, for example, there is no guarantee of any particular order. In practice, most engines maintain the order in which the keys were first declared, but V8 moves any numeric keys (e.g. `"1234"`) to the front, for a small performance gain. This was a [controversial issue](https://code.google.com/p/v8/issues/detail?id=164) – a lot of people think it sucks that you can't predict key enumeration order in Chrome – but the V8 team refused to 'fix' it, because it's not a bug, and they're right. If you want your values to be in a certain order, and you're relying on the non-standard key-ordering logic of a particular engine, then your code is broken. Restructure your data to use arrays.
55+
56+
##### But I just want it to be in order for readability
57+
58+
That would require manually parsing the JSON string with regular expressions (instead of using `JSON.parse`), which would be too slow. And it's not a good idea to go down the road of representing the data differently from how the engine actually sees it.

0 commit comments

Comments
 (0)