pretty-print

Use jq to Format Certain Fields as Compact?

*爱你&永不变心* 提交于 2020-01-11 12:38:05
问题 Is jq the best choice for pretty-printing arbitrary JSON? cat my.json | jq . pretty-prints the given JSON, but expands every field on a separate line. But what if some of the fields are repetitive, such as a list of points? How can fields that match a pattern be formatted on a single line with --compact-output ? For example, format "coords" and "list" fields below on a single line: [ { "field1": { "a": "", "b": "" "list": [{ "name": "x", "score": 1, "rect": { "x": 156, "y": 245, "w": 35, "h":

Python pretty print dictionary of lists, abbreviate long lists

北慕城南 提交于 2020-01-09 10:01:27
问题 I have a dictionary of lists and the lists are quite long. How can I print it in a way that only a few elements of the list show up? Obviously, I can write a custom function for that but is there any built-in way or library that can achieve this? For example when printing large data frames, pandas prints it nicely in a short way. This example better illustrates what I mean: obj = {'key_1': ['EG8XYD9FVN', 'S2WARDCVAO', 'J00YCU55DP', 'R07BUIF2F7', 'VGPS1JD0UM', 'WL3TWSDP8E', 'LD8QY7DMJ3',

Is it possible to skip outputting specific key and associated values in python json.dumps?

試著忘記壹切 提交于 2020-01-06 10:22:25
问题 Using json.dumps I have the following output. { "1": { "fooBar": { "_foo": "foo", "_bar": "bar", "_id": "1" }, "longValueList": [ [ 1, 2, ... n, ], ... The above output is generated using this class object function. def toJSON(self): return json.dumps(self._container, default=lambda o: o.__dict__, sort_keys=True, indent=4) The key longValueList is associated with really long value list and I do not need it printed when doing these specific json prints. How can prevent pythons json.dumps from

How to pretty print using jq, so that multiple values are on the same line?

爱⌒轻易说出口 提交于 2020-01-04 02:11:31
问题 What I get from jq is: { "frameGrid": { "size": [ 24, 24 ], "dimensions": [ 1, 1 ], "names": [ [ "default" ] ] } } What I would like to see is something more like this: { "frameGrid": { "size": [24,24], "dimensions": [1,1], "names": [["default"]] } } I know both forms are valid, and that jq has a compact/pretty print mode. But is there something in-between? I'm looking to somehow format a larger json file that has many more array values than this, so that it's easily readable and printable.

How to pretty-print QString with GoogleTest framework?

青春壹個敷衍的年華 提交于 2020-01-01 04:38:26
问题 I am using the GoogleTest (GTest) framework in conjunction with a Qt5 application. Whenever a test fails using a QString argument, the framework tries to print all the involved values. However, it cannot automatically handle foreign types (Qt5's QString in this case). QString test = "Test"; ASSERT_EQ(test, "Value"); How can I get GoogleTest to pretty print QStrings automatically (= without having to manually convert them each time)? 回答1: The GoogleTest Guide explains how you can in general

Freemarker print date in template

浪子不回头ぞ 提交于 2020-01-01 03:10:09
问题 I am trying to print the current date when the template is activated. I have read that I have to pass a new Date() Java object to the template, but I don't know how to do that or where to put it in the code. Does someone know how to pass a Java object to the template in this case? Thank you !! 回答1: Actually you don't have to pass a new Date() to your template, because placing a timestamp into a template's output is quite common and therefore FreeMarker provides a special variable called .now

Nice bit of code to format an xml string

假装没事ソ 提交于 2019-12-31 19:59:53
问题 Anyone got a ready made function that will take an XML string and return a correctly indented string? eg <XML><TAG1>A</TAG1><TAG2><Tag3></Tag3></TAG2></XML> and will return nicely formatted String in return after inserting linebreaks and tabs or spaces? 回答1: The RTL has FormatXMLData in XMLDoc.pas that accepts and returns strings. 回答2: Using OmniXML: program TestIndentXML; {$APPTYPE CONSOLE} uses SysUtils, OmniXML, OmniXMLUtils; function IndentXML(const xml: string): string; var xmlDoc:

best way to implement custom pretty-printers

坚强是说给别人听的谎言 提交于 2019-12-31 18:42:50
问题 Customizing pprint.PrettyPrinter The documentation for the pprint module mentions that the method PrettyPrinter.format is intended to make it possible to customize formatting. I gather that it's possible to override this method in a subclass, but this doesn't seem to provide a way to have the base class methods apply line wrapping and indentation. Am I missing something here? Is there a better way to do this (e.g. another module)? Alternatives? I've checked out the pretty module, which looks

best way to implement custom pretty-printers

本秂侑毒 提交于 2019-12-31 18:41:53
问题 Customizing pprint.PrettyPrinter The documentation for the pprint module mentions that the method PrettyPrinter.format is intended to make it possible to customize formatting. I gather that it's possible to override this method in a subclass, but this doesn't seem to provide a way to have the base class methods apply line wrapping and indentation. Am I missing something here? Is there a better way to do this (e.g. another module)? Alternatives? I've checked out the pretty module, which looks

Tab and pre wrapped around JSON output in Chrome

一笑奈何 提交于 2019-12-31 05:32:06
问题 I am using this simple code to print an array as a JSON structure. header('Content-Type: application/json'); echo json_encode($this->data, JSON_PRETTY_PRINT); I'm using Chrome Version 28.0.1500.95 m. For some odd reason the output is wrapped in a pre tag with a tab character (i.e. \t ) at the beginning. JSON seems to be parsing okay but I still get that tab character when no data is sent. How can I fix this ? <pre style="word-wrap: break-word; white-space: pre-wrap;"> { "title": "Node",