|
| 1 | +.. _ctags-json-output(5): |
| 2 | + |
| 3 | +============================================================== |
| 4 | +ctags-json-output |
| 5 | +============================================================== |
| 6 | + |
| 7 | +JSON based ctags output |
| 8 | + |
| 9 | +:Version: 1.0 |
| 10 | +:Manual group: Universal Ctags |
| 11 | +:Manual section: 5 |
| 12 | + |
| 13 | +SYNOPSIS |
| 14 | +-------- |
| 15 | +| **ctags** --output-format=json ... |
| 16 | +
|
| 17 | +DESCRIPTION |
| 18 | +----------- |
| 19 | +Universal Ctags supports `JSON <https://www.json.org/>`_ (strictly |
| 20 | +speaking `JSON Lines <https://jsonlines.org/>`_) output format if the |
| 21 | +ctags executable is built with ``libjansson``. JSON output goes to |
| 22 | +standard output by default. |
| 23 | + |
| 24 | +Format |
| 25 | +------ |
| 26 | +Each JSON line represents a tag. |
| 27 | + |
| 28 | +.. code-block:: console |
| 29 | +
|
| 30 | + $ ctags --extras=+p --output-format=json --fields=-s input.py |
| 31 | + {"_type": "ptag", "name": "JSON_OUTPUT_VERSION", "path": "1.0", "pattern": "in development"} |
| 32 | + {"_type": "ptag", "name": "TAG_FILE_SORTED", "path": "1", "pattern": "0=unsorted, 1=sorted, 2=foldcase"} |
| 33 | + ... |
| 34 | + {"_type": "tag", "name": "Klass", "path": "/tmp/input.py", "pattern": "/^class Klass:$/", "language": "Python", "kind": "class"} |
| 35 | + {"_type": "tag", "name": "method", "path": "/tmp/input.py", "pattern": "/^ def method(self):$/", "language": "Python", "kind": "member", "scope": "Klass", "scopeKind": "class"} |
| 36 | + ... |
| 37 | +
|
| 38 | +A key not starting with ``_`` is mapped to a field of ctags. |
| 39 | +"``--output-format=json --list-fields``" options list the fields. |
| 40 | + |
| 41 | +A key starting with ``_`` represents meta information of the JSON |
| 42 | +line. Currently only ``_type`` key is used. If the value for the key |
| 43 | +is ``tag``, the JSON line represents a regular tag. If the value is |
| 44 | +``ptag``, the line represents a pseudo-tag. |
| 45 | + |
| 46 | +The output format can be changed in the |
| 47 | +future. ``JSON_OUTPUT_VERSION`` pseudo-tag provides a change |
| 48 | +client-tools to handle the changes. Current version is "1.0". A |
| 49 | +client-tool can extract the version with ``path`` key from the |
| 50 | +pseudo-tag. |
| 51 | + |
| 52 | +The JSON output format is newly designed and has no limitation found |
| 53 | +in the default tags file format. |
| 54 | + |
| 55 | +* The values for ``kind`` key are represented in long-name flags. |
| 56 | + No one-letter is here. |
| 57 | + |
| 58 | +* Scope names and scope kinds have distinguished keys: ``scope`` and ``scopeKind``. |
| 59 | + They are combined in the default tags file format. |
| 60 | + |
| 61 | +Data type used in a field |
| 62 | +------------------------- |
| 63 | +Values for the most of all keys are represented in JSON string type. |
| 64 | +However, some of them are represented in string, integer, and/or boolean type. |
| 65 | + |
| 66 | +"``--output-format=json --list-fields``" options show What kind of data type |
| 67 | +used in a field of JSON. |
| 68 | + |
| 69 | +.. code-block:: console |
| 70 | +
|
| 71 | + $ ctags --output-format=json --list-fields |
| 72 | + #LETTER NAME ENABLED LANGUAGE JSTYPE FIXED DESCRIPTION |
| 73 | + F input yes NONE s-- no input file |
| 74 | + ... |
| 75 | + P pattern yes NONE s-b no pattern |
| 76 | + ... |
| 77 | + f file yes NONE --b no File-restricted scoping |
| 78 | + ... |
| 79 | + e end no NONE -i- no end lines of various items |
| 80 | + ... |
| 81 | +
|
| 82 | +``JSTYPE`` column shows the data types. |
| 83 | + |
| 84 | +'``s``' |
| 85 | + string |
| 86 | + |
| 87 | +'``i``' |
| 88 | + integer |
| 89 | + |
| 90 | +'``b``' |
| 91 | + boolean (true or false) |
| 92 | + |
| 93 | +For an example, the value for ``pattern`` field of ctags takes a string or a boolean value. |
| 94 | + |
| 95 | +VERSIONS |
| 96 | +-------- |
| 97 | + |
| 98 | +Cnages since "0.0" |
| 99 | +~~~~~~~~~~~~~~~~~~ |
| 100 | + |
| 101 | +* New key ``kindName`` for ``TAG_ROLE_DESCRIPTION`` pseudo tag |
| 102 | + |
| 103 | + ``kindName`` is added to store the name of the kind in ``TAG_ROLE_DESCRIPTION`` |
| 104 | + pseudo tags. |
| 105 | + |
| 106 | + In 0.0, a "TAG_ROLE_DESCRIPTION" pseudo tag was printed like: |
| 107 | + |
| 108 | + .. code-block:: JSON |
| 109 | +
|
| 110 | + {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", |
| 111 | + "parserName": "LANG!KIND", } |
| 112 | +
|
| 113 | + In 1.0, it is printed like: |
| 114 | + |
| 115 | + .. code-block:: JSON |
| 116 | +
|
| 117 | + {"_type": "ptag", "name": "TAG_ROLE_DESCRIPTION", |
| 118 | + "parserName": "LANG", |
| 119 | + "kindName": "KIND", } |
| 120 | +
|
| 121 | +SEE ALSO |
| 122 | +-------- |
| 123 | +:ref:`ctags(1) <ctags(1)>`, :ref:`tags(5) <tags(5)>`, :ref:`ctags-client-tools(7) <ctags-client-tools(7)>` |
0 commit comments