json.asciidoc 2.3 KB

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