json_parser.qbk 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. [/
  2. / Copyright (c) 2008 Marcin Kalicinski (kalita <at> poczta dot onet dot pl)
  3. / Copyright (c) 2009 Sebastian Redl (sebastian dot redl <at> getdesigned dot at)
  4. /
  5. / Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. /]
  8. [section JSON Parser]
  9. [def __json__ [@http://en.wikipedia.org/wiki/JSON JSON format]]
  10. The __json__ is a data interchange format derived from the object literal
  11. notation of JavaScript. (JSON stands for JavaScript Object Notation.)
  12. JSON is a simple, compact format for loosely structured node trees of any depth,
  13. very similar to the property tree dataset. It is less structured than XML and
  14. has no schema support, but has the advantage of being simpler, smaller and typed
  15. without the need for a complex schema.
  16. The property tree dataset is not typed, and does not support arrays as such.
  17. Thus, the following JSON / property tree mapping is used:
  18. * JSON objects are mapped to nodes. Each property is a child node.
  19. * JSON arrays are mapped to nodes. Each element is a child node with an empty
  20. name. If a node has both named and unnamed child nodes, it cannot be mapped
  21. to a JSON representation.
  22. * JSON values are mapped to nodes containing the value. However, all type
  23. information is lost; numbers, as well as the literals "null", "true" and
  24. "false" are simply mapped to their string form.
  25. * Property tree nodes containing both child nodes and data cannot be mapped.
  26. JSON round-trips, except for the type information loss.
  27. For example this JSON:
  28. {
  29. "menu":
  30. {
  31. "foo": true,
  32. "bar": "true",
  33. "value": 102.3E+06,
  34. "popup":
  35. [
  36. {"value": "New", "onclick": "CreateNewDoc()"},
  37. {"value": "Open", "onclick": "OpenDoc()"},
  38. ]
  39. }
  40. }
  41. will be translated into the following property tree:
  42. menu
  43. {
  44. foo true
  45. bar true
  46. value 102.3E+06
  47. popup
  48. {
  49. ""
  50. {
  51. value New
  52. onclick CreateNewDoc()
  53. }
  54. ""
  55. {
  56. value Open
  57. onclick OpenDoc()
  58. }
  59. }
  60. }
  61. [endsect] [/json_parser]