Skip to content

Commit 0048385

Browse files
committed
#307 PrettyPrint JSON
1 parent 01193e6 commit 0048385

File tree

8 files changed

+184
-39
lines changed

8 files changed

+184
-39
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning].
99

1010
-
1111

12-
## [0.9.6] - 2025-05-27
12+
## [0.9.6] - 2025-05-30
1313

1414
### Changed in 0.9.6
1515

szconfig/szconfig_examples_test.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ func ExampleSzconfig_AddDataSource() {
3737
handleError(err)
3838
}
3939

40-
fmt.Println(result)
41-
// Output: {"DSRC_ID":1001}
40+
fmt.Println(jsonutil.PrettyPrint(result, jsonIndentation))
41+
// Output:
42+
// {
43+
// "DSRC_ID": 1001
44+
// }
4245
}
4346

4447
func ExampleSzconfig_DeleteDataSource() {
@@ -114,8 +117,20 @@ func ExampleSzconfig_GetDataSources() {
114117
handleError(err)
115118
}
116119

117-
fmt.Println(result)
118-
// Output: {"DATA_SOURCES":[{"DSRC_ID":1,"DSRC_CODE":"TEST"},{"DSRC_ID":2,"DSRC_CODE":"SEARCH"}]}
120+
fmt.Println(jsonutil.PrettyPrint(result, jsonIndentation))
121+
// Output:
122+
// {
123+
// "DATA_SOURCES": [
124+
// {
125+
// "DSRC_ID": 1,
126+
// "DSRC_CODE": "TEST"
127+
// },
128+
// {
129+
// "DSRC_ID": 2,
130+
// "DSRC_CODE": "SEARCH"
131+
// }
132+
// ]
133+
// }
119134
}
120135

121136
// ----------------------------------------------------------------------------

szconfig/szconfig_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const (
2525
dataSourceCode = "GO_TEST"
2626
defaultTruncation = 76
2727
instanceName = "SzConfig Test"
28+
jsonIndentation = " "
2829
observerOrigin = "SzConfig observer"
2930
originMessage = "Machine: nn; Task: UnitTest"
3031
printErrors = false

szconfigmanager/szconfigmanager_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
const (
2727
defaultTruncation = 76
2828
instanceName = "SzConfigManager Test"
29+
jsonIndentation = " "
2930
observerOrigin = "SzConfigManager observer"
3031
originMessage = "Machine: nn; Task: UnitTest"
3132
printErrors = false

szdiagnostic/szdiagnostic_examples_test.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/senzing-garage/go-logging/logging"
1111
)
1212

13+
const AllLines = -1
14+
1315
// ----------------------------------------------------------------------------
1416
// Interface methods - Examples for godoc documentation
1517
// ----------------------------------------------------------------------------
@@ -32,8 +34,12 @@ func ExampleSzdiagnostic_CheckDatastorePerformance() {
3234
handleError(err)
3335
}
3436

35-
fmt.Println(jsonutil.Truncate(result, 2))
36-
// Output: {"insertTime":1000,...
37+
redactKeys := []string{"numRecordsInserted"}
38+
fmt.Println(jsonutil.PrettyPrint(jsonutil.Truncate(result, AllLines, redactKeys...), jsonIndentation))
39+
// Output:
40+
// {
41+
// "insertTime": 1000
42+
// }
3743
}
3844

3945
func ExampleSzdiagnostic_GetDatastoreInfo() {
@@ -52,8 +58,17 @@ func ExampleSzdiagnostic_GetDatastoreInfo() {
5258
handleError(err)
5359
}
5460

55-
fmt.Println(result)
56-
// Output: {"dataStores":[{"id":"CORE","type":"sqlite3","location":"nowhere"}]}
61+
fmt.Println(jsonutil.PrettyPrint(result, jsonIndentation))
62+
// Output:
63+
// {
64+
// "dataStores": [
65+
// {
66+
// "id": "CORE",
67+
// "type": "sqlite3",
68+
// "location": "nowhere"
69+
// }
70+
// ]
71+
// }
5772
}
5873

5974
func ExampleSzdiagnostic_GetFeature() {

szengine/szengine_examples_test.go

Lines changed: 114 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,17 @@ func ExampleSzengine_AddRecord_withInfo() {
8787
handleError(err)
8888
}
8989

90-
fmt.Println(result)
91-
// Output: {"DATA_SOURCE":"CUSTOMERS","RECORD_ID":"1003","AFFECTED_ENTITIES":[{"ENTITY_ID":100001}]}
90+
fmt.Println(jsonutil.PrettyPrint(result, jsonIndentation))
91+
// Output:
92+
// {
93+
// "DATA_SOURCE": "CUSTOMERS",
94+
// "RECORD_ID": "1003",
95+
// "AFFECTED_ENTITIES": [
96+
// {
97+
// "ENTITY_ID": 100001
98+
// }
99+
// ]
100+
// }
92101
}
93102

94103
func ExampleSzengine_CloseExport() {
@@ -180,8 +189,13 @@ func ExampleSzengine_DeleteRecord_withInfo() {
180189
handleError(err)
181190
}
182191

183-
fmt.Println(result)
184-
// Output: {"DATA_SOURCE":"CUSTOMERS","RECORD_ID":"1003","AFFECTED_ENTITIES":[]}
192+
fmt.Println(jsonutil.PrettyPrint(result, jsonIndentation))
193+
// Output:
194+
// {
195+
// "DATA_SOURCE": "CUSTOMERS",
196+
// "RECORD_ID": "1003",
197+
// "AFFECTED_ENTITIES": []
198+
// }
185199
}
186200

187201
func ExampleSzengine_ExportCsvEntityReport() {
@@ -339,8 +353,13 @@ func ExampleSzengine_FindInterestingEntitiesByEntityID() {
339353
handleError(err)
340354
}
341355

342-
fmt.Println(result)
343-
// Output: {"INTERESTING_ENTITIES":{"ENTITIES":[]}}
356+
fmt.Println(jsonutil.PrettyPrint(result, jsonIndentation))
357+
// Output:
358+
// {
359+
// "INTERESTING_ENTITIES": {
360+
// "ENTITIES": []
361+
// }
362+
// }
344363
}
345364

346365
func ExampleSzengine_FindInterestingEntitiesByRecordID() {
@@ -363,8 +382,13 @@ func ExampleSzengine_FindInterestingEntitiesByRecordID() {
363382
handleError(err)
364383
}
365384

366-
fmt.Println(result)
367-
// Output: {"INTERESTING_ENTITIES":{"ENTITIES":[]}}
385+
fmt.Println(jsonutil.PrettyPrint(result, jsonIndentation))
386+
// Output:
387+
// {
388+
// "INTERESTING_ENTITIES": {
389+
// "ENTITIES": []
390+
// }
391+
// }
368392
}
369393

370394
func ExampleSzengine_FindNetworkByEntityID() {
@@ -391,8 +415,18 @@ func ExampleSzengine_FindNetworkByEntityID() {
391415
handleError(err)
392416
}
393417

394-
fmt.Println(result)
395-
// Output: {"ENTITY_PATHS":[],"ENTITIES":[{"RESOLVED_ENTITY":{"ENTITY_ID":100001}}]}
418+
fmt.Println(jsonutil.PrettyPrint(result, jsonIndentation))
419+
// Output:
420+
// {
421+
// "ENTITY_PATHS": [],
422+
// "ENTITIES": [
423+
// {
424+
// "RESOLVED_ENTITY": {
425+
// "ENTITY_ID": 100001
426+
// }
427+
// }
428+
// ]
429+
// }
396430
}
397431

398432
func ExampleSzengine_FindNetworkByEntityID_output() {
@@ -504,8 +538,18 @@ func ExampleSzengine_FindNetworkByRecordID() {
504538
handleError(err)
505539
}
506540

507-
fmt.Println(result)
508-
// Output: {"ENTITY_PATHS":[],"ENTITIES":[{"RESOLVED_ENTITY":{"ENTITY_ID":100001}}]}
541+
fmt.Println(jsonutil.PrettyPrint(result, jsonIndentation))
542+
// Output:
543+
// {
544+
// "ENTITY_PATHS": [],
545+
// "ENTITIES": [
546+
// {
547+
// "RESOLVED_ENTITY": {
548+
// "ENTITY_ID": 100001
549+
// }
550+
// }
551+
// ]
552+
// }
509553
}
510554

511555
func ExampleSzengine_FindNetworkByRecordID_output() {
@@ -1298,8 +1342,13 @@ func ExampleSzengine_GetEntityByEntityID() {
12981342
handleError(err)
12991343
}
13001344

1301-
fmt.Println(result)
1302-
// Output: {"RESOLVED_ENTITY":{"ENTITY_ID":100001}}
1345+
fmt.Println(jsonutil.PrettyPrint(result, jsonIndentation))
1346+
// Output:
1347+
// {
1348+
// "RESOLVED_ENTITY": {
1349+
// "ENTITY_ID": 100001
1350+
// }
1351+
// }
13031352
}
13041353

13051354
func ExampleSzengine_GetEntityByEntityID_output() {
@@ -1513,8 +1562,13 @@ func ExampleSzengine_GetEntityByRecordID() {
15131562
handleError(err)
15141563
}
15151564

1516-
fmt.Println(result)
1517-
// Output: {"RESOLVED_ENTITY":{"ENTITY_ID":100001}}
1565+
fmt.Println(jsonutil.PrettyPrint(result, jsonIndentation))
1566+
// Output:
1567+
// {
1568+
// "RESOLVED_ENTITY": {
1569+
// "ENTITY_ID": 100001
1570+
// }
1571+
// }
15181572
}
15191573

15201574
func ExampleSzengine_GetEntityByRecordID_output() {
@@ -1728,8 +1782,12 @@ func ExampleSzengine_GetRecord() {
17281782
handleError(err)
17291783
}
17301784

1731-
fmt.Println(jsonutil.Flatten(jsonutil.Normalize(result)))
1732-
// Output: {"DATA_SOURCE":"CUSTOMERS","RECORD_ID":"1001"}
1785+
fmt.Println(jsonutil.PrettyPrint(jsonutil.Flatten(jsonutil.Normalize(result)), jsonIndentation))
1786+
// Output:
1787+
// {
1788+
// "DATA_SOURCE": "CUSTOMERS",
1789+
// "RECORD_ID": "1001"
1790+
// }
17331791
}
17341792

17351793
func ExampleSzengine_GetRedoRecord() {
@@ -2065,8 +2123,13 @@ func ExampleSzengine_GetVirtualEntityByRecordID() {
20652123
handleError(err)
20662124
}
20672125

2068-
fmt.Println(result)
2069-
// Output: {"RESOLVED_ENTITY":{"ENTITY_ID":100001}}
2126+
fmt.Println(jsonutil.PrettyPrint(result, jsonIndentation))
2127+
// Output:
2128+
// {
2129+
// "RESOLVED_ENTITY": {
2130+
// "ENTITY_ID": 100001
2131+
// }
2132+
// }
20702133
}
20712134

20722135
func ExampleSzengine_GetVirtualEntityByRecordID_output() {
@@ -3041,8 +3104,17 @@ func ExampleSzEngine_ProcessRedoRecord_withInfo() {
30413104
handleError(err)
30423105
}
30433106

3044-
fmt.Println(result)
3045-
// Output: {"DATA_SOURCE":"CUSTOMERS","RECORD_ID":"1001","AFFECTED_ENTITIES":[{"ENTITY_ID":100001}]}
3107+
fmt.Println(jsonutil.PrettyPrint(result, jsonIndentation))
3108+
// Output:
3109+
// {
3110+
// "DATA_SOURCE": "CUSTOMERS",
3111+
// "RECORD_ID": "1001",
3112+
// "AFFECTED_ENTITIES": [
3113+
// {
3114+
// "ENTITY_ID": 100001
3115+
// }
3116+
// ]
3117+
// }
30463118
}
30473119

30483120
func ExampleSzengine_ReevaluateEntity() {
@@ -3088,8 +3160,15 @@ func ExampleSzengine_ReevaluateEntity_withInfo() {
30883160
handleError(err)
30893161
}
30903162

3091-
fmt.Println(result)
3092-
// Output: {"AFFECTED_ENTITIES":[{"ENTITY_ID":100001}]}
3163+
fmt.Println(jsonutil.PrettyPrint(result, jsonIndentation))
3164+
// Output:
3165+
// {
3166+
// "AFFECTED_ENTITIES": [
3167+
// {
3168+
// "ENTITY_ID": 100001
3169+
// }
3170+
// ]
3171+
// }
30933172
}
30943173

30953174
func ExampleSzengine_ReevaluateRecord() {
@@ -3136,8 +3215,17 @@ func ExampleSzengine_ReevaluateRecord_withInfo() {
31363215
handleError(err)
31373216
}
31383217

3139-
fmt.Println(result)
3140-
// Output: {"DATA_SOURCE":"CUSTOMERS","RECORD_ID":"1001","AFFECTED_ENTITIES":[{"ENTITY_ID":100001}]}
3218+
fmt.Println(jsonutil.PrettyPrint(result, jsonIndentation))
3219+
// Output:
3220+
// {
3221+
// "DATA_SOURCE": "CUSTOMERS",
3222+
// "RECORD_ID": "1001",
3223+
// "AFFECTED_ENTITIES": [
3224+
// {
3225+
// "ENTITY_ID": 100001
3226+
// }
3227+
// ]
3228+
// }
31413229
}
31423230

31433231
func ExampleSzengine_SearchByAttributes() {

szproduct/szproduct_examples_test.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/senzing-garage/go-logging/logging"
1111
)
1212

13+
const AllLines = -1
14+
1315
// ----------------------------------------------------------------------------
1416
// Interface methods - Examples for godoc documentation
1517
// ----------------------------------------------------------------------------
@@ -30,8 +32,17 @@ func ExampleSzproduct_GetLicense() {
3032
handleError(err)
3133
}
3234

33-
fmt.Println(jsonutil.Truncate(result, 4))
34-
// Output: {"billing":"YEARLY","contract":"Senzing Public Test License","customer":"Senzing Public Test License",...
35+
redactKeys := []string{"issueDate", "expireDate", "BUILD_VERSION"}
36+
fmt.Println(jsonutil.PrettyPrint(jsonutil.Truncate(result, AllLines, redactKeys...), jsonIndentation))
37+
// Output:
38+
// {
39+
// "billing": "YEARLY",
40+
// "contract": "Senzing Public Test License",
41+
// "customer": "Senzing Public Test License",
42+
// "licenseLevel": "STANDARD",
43+
// "licenseType": "EVAL (Solely for non-productive use)",
44+
// "recordLimit": 50000
45+
// }
3546
}
3647

3748
func ExampleSzproduct_GetVersion() {
@@ -50,8 +61,21 @@ func ExampleSzproduct_GetVersion() {
5061
handleError(err)
5162
}
5263

53-
fmt.Println(truncate(result, 43))
54-
// Output: {"PRODUCT_NAME":"Senzing SDK","VERSION":...
64+
redactKeys := []string{"BUILD_DATE", "BUILD_NUMBER", "BUILD_VERSION"}
65+
fmt.Println(jsonutil.PrettyPrint(jsonutil.Truncate(result, AllLines, redactKeys...), jsonIndentation))
66+
// Output:
67+
// {
68+
// "COMPATIBILITY_VERSION": {
69+
// "CONFIG_VERSION": "11"
70+
// },
71+
// "PRODUCT_NAME": "Senzing SDK",
72+
// "SCHEMA_VERSION": {
73+
// "ENGINE_SCHEMA_VERSION": "4.0",
74+
// "MAXIMUM_REQUIRED_SCHEMA_VERSION": "4.99",
75+
// "MINIMUM_REQUIRED_SCHEMA_VERSION": "4.0"
76+
// },
77+
// "VERSION": "4.0.0"
78+
// }
5579
}
5680

5781
// ----------------------------------------------------------------------------

szproduct/szproduct_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
const (
2323
defaultTruncation = 76
2424
instanceName = "SzProduct Test"
25+
jsonIndentation = " "
2526
observerOrigin = "SzProduct observer"
2627
originMessage = "Machine: nn; Task: UnitTest"
2728
printErrors = false

0 commit comments

Comments
 (0)