json.asciidoc 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 that the converted structured object will be written into. Any existing content in this field will be overwritten.
  14. | `add_to_root` | no | false | Flag that forces the parsed JSON to be added at the top level of the document. `target_field` must not be set when this option is chosen.
  15. | `add_to_root_conflict_strategy` | no | `replace` | When set to `replace`, root fields that conflict with fields from the parsed JSON will be overridden. When set to `merge`, conflicting fields will be merged. Only applicable if `add_to_root` is set to `true`.
  16. | `allow_duplicate_keys` | no | false | When set to `true`, the JSON parser will not fail if the JSON contains duplicate keys. Instead, the last encountered value for any duplicate key wins.
  17. include::common-options.asciidoc[]
  18. |======
  19. All JSON-supported types will be parsed (null, boolean, number, array, object, string).
  20. Suppose you provide this configuration of the `json` processor:
  21. [source,js]
  22. --------------------------------------------------
  23. {
  24. "json" : {
  25. "field" : "string_source",
  26. "target_field" : "json_target"
  27. }
  28. }
  29. --------------------------------------------------
  30. // NOTCONSOLE
  31. If the following document is processed:
  32. [source,js]
  33. --------------------------------------------------
  34. {
  35. "string_source": "{\"foo\": 2000}"
  36. }
  37. --------------------------------------------------
  38. // NOTCONSOLE
  39. after the `json` processor operates on it, it will look like:
  40. [source,js]
  41. --------------------------------------------------
  42. {
  43. "string_source": "{\"foo\": 2000}",
  44. "json_target": {
  45. "foo": 2000
  46. }
  47. }
  48. --------------------------------------------------
  49. // NOTCONSOLE
  50. If the following configuration is provided, omitting the optional `target_field` setting:
  51. [source,js]
  52. --------------------------------------------------
  53. {
  54. "json" : {
  55. "field" : "source_and_target"
  56. }
  57. }
  58. --------------------------------------------------
  59. // NOTCONSOLE
  60. then after the `json` processor operates on this document:
  61. [source,js]
  62. --------------------------------------------------
  63. {
  64. "source_and_target": "{\"foo\": 2000}"
  65. }
  66. --------------------------------------------------
  67. // NOTCONSOLE
  68. it will look like:
  69. [source,js]
  70. --------------------------------------------------
  71. {
  72. "source_and_target": {
  73. "foo": 2000
  74. }
  75. }
  76. --------------------------------------------------
  77. // NOTCONSOLE
  78. This illustrates that, unless it is explicitly named in the processor configuration, the `target_field`
  79. is the same field provided in the required `field` configuration.