Hasty Briefsbeta

How many valid JSON strings are there?

a day ago
  • #Unicode
  • #grammar
  • #JSON
  • A valid JSON string must conform to the grammar described at json.org.
  • Unicode provides an alphabet of 1,114,112 possible characters, numbered from 0x0000 to 0x10FFFF.
  • JSON strings are measured in characters, not bytes, simplifying the task.
  • Valid JSON strings include 'null', 'true', 'false', numbers, and stringified strings like '"ab"'.
  • Whitespace in JSON includes space, tab, carriage return, and line feed, multiplying possibilities by 4^N.
  • JSON numbers can be in formats like 123, 123.456, 123e456, and 123.456e789, with specific exponent symbols.
  • Stringified strings dominate the count of valid JSON strings, especially for lengths N ≥ 3.
  • The smallest JSON object is '{}' (N=2), and the smallest non-empty object is '{"":0}' (N=6).
  • Duplicate keys in JSON objects are allowed, which simplifies counting but may cause interpretation issues.
  • The number of valid JSON strings grows exponentially with length, with detailed counts provided up to N=10.