Skip to content
Snippets Groups Projects
Commit 8aaed22a authored by Bensong Liu's avatar Bensong Liu
Browse files

init

parent 9c680987
No related branches found
No related tags found
No related merge requests found
module json2table
go 1.16
require github.com/tidwall/gjson v1.6.8
github.com/tidwall/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w=
github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
package main
import "os"
import "github.com/tidwall/gjson"
const json = "[\n {\n \"attributes\": {\n \"created\": \"2020-11-30T07:41:31+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-11-30T07:41:31+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/AzcisConnectionStringKey\",\n \"managed\": null,\n \"name\": \"AzcisConnectionStringKey\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2021-02-24T02:47:16+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2021-02-24T02:47:16+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/AzureKeyVaultAppId\",\n \"managed\": null,\n \"name\": \"AzureKeyVaultAppId\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-12-16T09:29:55+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-12-16T09:29:55+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/BACPACURL\",\n \"managed\": null,\n \"name\": \"BACPACURL\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2021-02-18T07:40:24+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2021-02-18T07:40:24+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/BootstrapPocStorageAccount\",\n \"managed\": null,\n \"name\": \"BootstrapPocStorageAccount\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-12-28T10:48:00+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-12-28T10:48:00+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/CAAdminPassword\",\n \"managed\": null,\n \"name\": \"CAAdminPassword\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-11-12T08:34:10+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-11-12T08:34:10+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/CAAdminUserName\",\n \"managed\": null,\n \"name\": \"CAAdminUserName\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-12-29T02:25:57+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-12-29T02:25:57+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/CAOneclickVHDTest\",\n \"managed\": null,\n \"name\": \"CAOneclickVHDTest\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2021-01-07T05:37:44+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2021-01-07T05:37:44+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/CAVHDUri\",\n \"managed\": null,\n \"name\": \"CAVHDUri\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-12-23T10:00:51+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-12-23T10:00:51+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/ClientSecret\",\n \"managed\": null,\n \"name\": \"ClientSecret\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-09-11T05:37:11+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-09-11T05:37:11+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/ConnectStringofBootstrapStorage\",\n \"managed\": null,\n \"name\": \"ConnectStringofBootstrapStorage\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-09-17T16:37:35+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-09-17T16:37:35+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/DC1AdminPassword\",\n \"managed\": null,\n \"name\": \"DC1AdminPassword\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-09-15T08:22:25+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-09-15T08:22:25+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/DC1AdminUserName\",\n \"managed\": null,\n \"name\": \"DC1AdminUserName\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-09-17T16:37:47+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-09-17T16:37:47+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/DC2AdminPassword\",\n \"managed\": null,\n \"name\": \"DC2AdminPassword\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-09-15T08:38:39+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-09-15T08:38:39+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/DC2AdminUserName\",\n \"managed\": null,\n \"name\": \"DC2AdminUserName\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-12-23T06:28:22+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-12-23T06:28:22+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/DCCapacityBacpacUrl\",\n \"managed\": null,\n \"name\": \"DCCapacityBacpacUrl\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-09-21T07:03:48+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-09-21T07:03:48+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/DemoAdminPassword\",\n \"managed\": null,\n \"name\": \"DemoAdminPassword\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-09-21T07:03:30+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-09-21T07:03:30+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/DemoAdminUserName\",\n \"managed\": null,\n \"name\": \"DemoAdminUserName\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-12-23T06:24:46+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-12-23T06:24:46+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/FleetAGCPOCSQLPassword\",\n \"managed\": null,\n \"name\": \"FleetAGCPOCSQLPassword\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-12-23T06:24:19+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-12-23T06:24:19+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/FleetAGCPOCSQLUserName\",\n \"managed\": null,\n \"name\": \"FleetAGCPOCSQLUserName\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-09-03T07:56:57+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-09-03T07:56:57+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/M365FleetAGCContributorSecret\",\n \"managed\": null,\n \"name\": \"M365FleetAGCContributorSecret\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2021-01-15T09:18:24+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2021-01-15T09:18:24+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/pfxpassword\",\n \"managed\": null,\n \"name\": \"pfxpassword\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2021-02-23T07:37:18+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2021-02-23T07:37:18+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/PrivateBootstrapStorageAccount\",\n \"managed\": null,\n \"name\": \"PrivateBootstrapStorageAccount\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2021-02-22T08:59:34+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2021-02-22T08:59:34+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/PrivateCAVHDUri\",\n \"managed\": null,\n \"name\": \"PrivateCAVHDUri\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-09-14T10:01:36+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-09-14T10:01:36+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/RecolicTestToken\",\n \"managed\": null,\n \"name\": \"RecolicTestToken\",\n \"tags\": {\n \"file-encoding\": \"utf-8\"\n }\n },\n {\n \"attributes\": {\n \"created\": \"2020-12-08T08:37:11+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-12-08T08:37:11+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/SQLPassword\",\n \"managed\": null,\n \"name\": \"SQLPassword\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-12-08T08:36:34+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-12-08T08:36:34+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/SQLUserName\",\n \"managed\": null,\n \"name\": \"SQLUserName\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-12-16T09:28:55+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-12-16T09:28:55+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/StorageAccountKey\",\n \"managed\": null,\n \"name\": \"StorageAccountKey\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-09-22T05:25:00+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-09-22T05:25:00+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/test-leila-pass\",\n \"managed\": null,\n \"name\": \"test-leila-pass\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-09-22T05:24:38+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-09-22T05:24:38+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/test-leila-username\",\n \"managed\": null,\n \"name\": \"test-leila-username\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2021-02-07T06:04:48+00:00\",\n \"enabled\": true,\n \"expires\": \"2022-02-04T06:37:15+00:00\",\n \"notBefore\": \"2021-02-04T06:27:15+00:00\",\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2021-02-07T06:04:48+00:00\"\n },\n \"contentType\": \"application/x-pkcs12\",\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/TestCert\",\n \"managed\": null,\n \"name\": \"TestCert\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-09-08T09:12:33+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-09-08T09:12:33+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/testvm-shuxli-password\",\n \"managed\": null,\n \"name\": \"testvm-shuxli-password\",\n \"tags\": null\n },\n {\n \"attributes\": {\n \"created\": \"2020-09-08T09:11:32+00:00\",\n \"enabled\": true,\n \"expires\": null,\n \"notBefore\": null,\n \"recoveryLevel\": \"Recoverable+Purgeable\",\n \"updated\": \"2020-09-08T09:11:32+00:00\"\n },\n \"contentType\": null,\n \"id\": \"https://fleetagcorchestration.vault.azure.net/secrets/testvm-shuxli-username\",\n \"managed\": null,\n \"name\": \"testvm-shuxli-username\",\n \"tags\": null\n }\n]\n"
func main() {
if len(os.Args) > 2 || (len(os.Args) == 2 && os.Args[1] == "-h") {
println("Usage: cat MyDataset.json | ./json2table")
println("Usage: cat MyDataset.json | ./json2table /path/to/object")
os.Exit(1)
}
value := gjson.Parse(json)
if value.IsArray() {
res_arr := value.Array()
for _, item := range res_arr {
println("ITEM=", item.Raw)
if item.IsObject() {
m := item.Map()
for key, value := range m {
result_str := value.Str
if value.IsArray() {
result_str = "ARRAY"
} else if value.IsObject() {
result_str = "OBJECT"
}
println("DEBUG: KV: " + key + "=" + result_str)
}
} else if item.IsArray() {
// array row
} else {
// single item row
}
}
}
println(value.Type)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment