How to pretty print json of a string field

Hi all,
is there a way to pretty print a json which is stored inside a string field? Right now Kibana visualize it in a 1 row, like this:

payload: { "name":"John", "age":30, "car":null }

This is what I would like to have:

payload:

{
"name": "John",
"age": 30,
"car": null
}

Can't find a way of doing that (I checked field formatter but it doesn't offer this choice).
Thanks,

Andrea

Hi @ea1987,

unfortunately there is no JSON field formatter yet. If you like you can open an enhancement request for that on GitHub. We are also open to receiving community PRs implementing such features. :wink:

Hi @weltenwort,
thank you for your answer. I'm trying to build my own JSON field formatter, but I'm facing some issues while developing it (it's my first plugin and I can't find any updated how-to doc). I have just written down the plugin skeleton, leaving text and html function almost empty, just to check that everything works. This is basically the public/.js file:

function stringifyJson (Private) {

  var _ = require('lodash');
  var FieldFormat = Private(require('ui/index_patterns/_field_format/field_format'));

  _.class(jsonFormat).inherits(FieldFormat);
  function jsonFormat(params) {
    jsonFormat.Super.call(this, params);
  }

  jsonFormat.id = 'jsonFormat';
  jsonFormat.title = 'Jsoncode';
  jsonFormat.fieldType = [

    'string',

  ];

  jsonFormat.prototype._convert = {

    text: function (value) {

      return value;

    },

    html: function (value) {

      return value;

    }

  };
  return jsonFormat;

}

 require('ui/registry/field_formats').register(stringifyJson);

Everything seems to be fine according to Kibana's log, but this is the message I receive when I open Kibana:

Error: Object doesn't support property or method 'register' (http://localhost:5601/bundles/kibana.bundle.js?v=15443:262)
   at window.onerror (http://localhost:5601/bundles/commons.bundle.js?v=15443:76:8856)

I suspect there is something wrong with this:

require('ui/registry/field_formats').register(stringifyJson);

But I don't know how to fix it.
Can you please help me?
Thanks,

Andrea

The module ui/registry/field_formats does not export the registry as the default export, but under the name RegistryFieldFormatsProvider. That means that it should be something like

require('ui/registry/field_formats').RegistryFieldFormatsProvider.register(stringifyJson);

Hi @weltenwort
Thank you for your suggestion. I tried that suggested code, now Kibana starts correctly but it doesn't show ui pages properly. I checked via console and found these 2 errors

TypeError: Expected private module "[object Object]" to be a function
    at identify (commons.bundle.js?v=15443:82)
    at Private (commons.bundle.js?v=15443:82)
    at Object.stringifyJson (kibana.bundle.js?v=15443:262)
    at Object.invoke (commons.bundle.js?v=15443:36)
    at instantiate (commons.bundle.js?v=15443:82)
    at get (commons.bundle.js?v=15443:82)
    at Private (commons.bundle.js?v=15443:82)
    at Array.map (<anonymous>)
    at Object.registry (commons.bundle.js?v=15443:84)
    at Object.invoke (commons.bundle.js?v=15443:36)
commons.bundle.js?v=15443:38 Error: Circular reference to "IndexPatternsProvider" found while resolving private deps: IndexPatternsProvider -> IndexPatternProvider -> registry -> stringifyJson
    at instantiate (commons.bundle.js?v=15443:82)
    at get (commons.bundle.js?v=15443:82)
    at Private (commons.bundle.js?v=15443:82)
    at new <anonymous> (kibana.bundle.js?v=15443:27)
    at invoke (commons.bundle.js?v=15443:36)
    at Object.instantiate (commons.bundle.js?v=15443:36)
    at Object.<anonymous> (commons.bundle.js?v=15443:35)
    at Object.invoke (commons.bundle.js?v=15443:36)
    at Object.$get (commons.bundle.js?v=15443:35)
    at Object.invoke (commons.bundle.js?v=15443:36)

Do you know what's about?
Thanks,

Andrea

Hm, that path ui/index_patterns/_field_format/field_format indicates that you are not using the latest Kibana version. Which version do you try to develop for?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.