Cobra Interactive Query Language json output format


json output format


	json [message]
	json+ [message]


The json output format option is primarily meant to be used for summarizing the results of a pattern search with the pe command. The json output can be triggered automatically when the pattern search is done with a command line option (-pe 'pattern' by adding command line option -json. When the pattern search is performed interactively with the pe command, matches are preserved by marking tokens, and the results can be displayed with any of the display commands, or summarized with the json command.
The command is supported starting with Cobra Version 3.3 from Jan 28, 2021. The standard method is to issue the command followed by a message. In this form, the json format is generated with the text of the message (up to the newline or the first semicolon command separator) used for the type field of each report. The message argument can also be omitted, in which case the type field is left empty.

The json+ command (added in Version 3.4 from Feb 23, 2021) optionally adds two extra fields to the output format. The first added line contains the first line of the source text fragment that is matched (with double-quotes replaced with single-quotes and escape characters replaced by spaces), and, if available, the values of any variable bindings that were used to match the pattern.


	$ cobra *.c
	: pe while ( ^[< > <= >= == !=]* )
	10 patterns matched
	52 tokens marked
	: json while conditions without boolean operators
	  { "type"      :       "while conditions without boolean operators",
	    "message"   :       "lines 209..209",
	    "file"      :       "cobra_te.c",
	    "line"      :       209
	: json+	# in this example, an empty type field, no bindings
	  { "type"      :       " ",
	    "message"   :       "lines 209..209",
	    "source"    :       "while (bnd)",
	    "file"      :       "cobra_te.c",
	    "line"      :       209
	: dp 1	# display pattern 1
	   209                   while (bnd)


When this command is used to display the result of other types of query results (anything other than a pattern search with pe), an attempt is made to find ranges of marked tokens, that will then each be reported in json format. Other types of marked tokens are reported as single-line matches.

See pattern expressions for the specific numeric markings that the pe command uses to mark matches (which is a binary combination of numbers 1, 2, 4, and 8).

Another method to display the results of a pattern match as regular source text is to use the dp command.


pattern searches, dp display matched patterns, pe pattern expressions, display, list, pre,

Return to index
(Last Updated: 23 February 2021)