Cobra Interactive Query Language json output format

NAME

json output format

SYNTAX

	json [message]
	json+ [message]
	json_format [on/off]
	json_plus [on/off]

DESCRIPTION

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.

New in version 4.0 are the two commands json_format on/off and json_plus on/off, which generate no output but set a mode for future output generating commands like dp. Their effect is similar to the use (on) or non-use (off) of the command-line options -json and -json+.

EXAMPLES

	$ cobra *.c
	: pe while ( ^[< > <= >= == !=]* )
	74 patterns matched
	648 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
	cobra_te.c:209..209
	   209                   while (bnd)
	: q
	$ cobra *.c
	: pe A: while ( ^[< > <= >= == !=]* )
	74 patterns matched
	648 tokens marked
	: json_format on
	: dp A
	...
	:	
When using named pattern sets, the resulting matches of a given pattern should first be converted into token markings before the json is issued, as in:
	: pe A: while ( ^[< > <= >= == !=]* )
	74 patterns stored in set 'A'
	: r	# clear previous markings
	: ps convert A
	648 tokens marked
	: json suspicious while conditions
	...
Use the track to divert the output into a file when needed. For instance:
	: track start results.json
	: json message
	: track stop
	: !cat results.json

NOTES

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.

SEE ALSO

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

Return to index
Manual
Tutorial
(Last Updated: 2 December 2021)