1
0

json.asciidoc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. [[json-processor]]
  2. === JSON processor
  3. ++++
  4. <titleabbrev>JSON</titleabbrev>
  5. ++++
  6. Converts a JSON string into a structured JSON object.
  7. [[json-options]]
  8. .Json Options
  9. [options="header"]
  10. |======
  11. | Name | Required | Default | Description
  12. | `field` | yes | - | The field to be parsed
  13. | `target_field` | no | `field` | The field to insert the converted structured object into
  14. | `add_to_root` | no | false | Flag that forces the serialized json to be injected into the top level of the document. `target_field` must not be set when this option is chosen.
  15. include::common-options.asciidoc[]
  16. |======
  17. All JSON-supported types will be parsed (null, boolean, number, array, object, string).
  18. Suppose you provide this configuration of the `json` processor:
  19. [source,js]
  20. --------------------------------------------------
  21. {
  22. "json" : {
  23. "field" : "string_source",
  24. "target_field" : "json_target"
  25. }
  26. }
  27. --------------------------------------------------
  28. // NOTCONSOLE
  29. If the following document is processed:
  30. [source,js]
  31. --------------------------------------------------
  32. {
  33. "string_source": "{\"foo\": 2000}"
  34. }
  35. --------------------------------------------------
  36. // NOTCONSOLE
  37. after the `json` processor operates on it, it will look like:
  38. [source,js]
  39. --------------------------------------------------
  40. {
  41. "string_source": "{\"foo\": 2000}",
  42. "json_target": {
  43. "foo": 2000
  44. }
  45. }
  46. --------------------------------------------------
  47. // NOTCONSOLE
  48. If the following configuration is provided, omitting the optional `target_field` setting:
  49. [source,js]
  50. --------------------------------------------------
  51. {
  52. "json" : {
  53. "field" : "source_and_target"
  54. }
  55. }
  56. --------------------------------------------------
  57. // NOTCONSOLE
  58. then after the `json` processor operates on this document:
  59. [source,js]
  60. --------------------------------------------------
  61. {
  62. "source_and_target": "{\"foo\": 2000}"
  63. }
  64. --------------------------------------------------
  65. // NOTCONSOLE
  66. it will look like:
  67. [source,js]
  68. --------------------------------------------------
  69. {
  70. "source_and_target": {
  71. "foo": 2000
  72. }
  73. }
  74. --------------------------------------------------
  75. // NOTCONSOLE
  76. This illustrates that, unless it is explicitly named in the processor configuration, the `target_field`
  77. is the same field provided in the required `field` configuration.