[ JSON ] jq »ç¿ë¹ý ¹®ÀÇ

   Á¶È¸ 1928   Ãßõ 0    

아래의 문서를 json형식으로 판단이 되어 지는데, 가독성이 좋게 출력할 수 있는 방법이 있을런지요 ?
아시는 분의 조언 부탁 드립니다.


❯ cat a1
{
    "DecodedMessage":
"{\"allowed\":false,\"explicitDeny\":false,\"matchedStatements\":{\"items\":[]},\"failures\":{\"items\":[]},\"context\":{\"principal\":{\"id\":\"ABCDEFGHIJKLMNO\",\"name\":\"AWS-User\", \"arn\":\"arn:aws:iam::accountID:user/test-user\"},\"action\":\"iam:PassRole\", \"resource\":\"arn:aws:iam::accountID:role/EC2_instance_Profile_role\",\"conditions\":{\"items\":[{\"key\":\"aws:Region\",\"values\":{\"items\":[{\"value\":\"us-east-2\"}]}}, {\"key\":\"aws:Service\",\"values\":{\"items\":[{\"value\":\"ec2\"}]}},{\"key\":\"aws:Resource\",\"values\":{\"items\":[{\"value\":\"role/EC2_instance_Profile_role\"}]}}, {\"key\":\"iam:RoleName\",\"values\":{\"items\":[{\"value\":\"EC2_instance_Profile_role\"}]}},{\"key\":\"aws:Account\",\"values\":{\"items\":[{\"value\":\"accountID\"}]}}, {\"key\":\"aws:Type\",\"values\":{\"items\":[{\"value\":\"role\"}]}},{\"key\":\"aws:ARN\",\"values\":{\"items\":[{\"value\":\"arn:aws:iam::accountID:role/EC2_instance_Profile_role\"}]}}]}}}"
}


❯ \cat a1 | jq
{
  "DecodedMessage": "{\"allowed\":false,\"explicitDeny\":false,\"matchedStatements\":{\"items\":[]},\"failures\":{\"items\":[]},\"context\":{\"principal\":{\"id\":\"ABCDEFGHIJKLMNO\",\"name\":\"AWS-User\", \"arn\":\"arn:aws:iam::accountID:user/test-user\"},\"action\":\"iam:PassRole\", \"resource\":\"arn:aws:iam::accountID:role/EC2_instance_Profile_role\",\"conditions\":{\"items\":[{\"key\":\"aws:Region\",\"values\":{\"items\":[{\"value\":\"us-east-2\"}]}}, {\"key\":\"aws:Service\",\"values\":{\"items\":[{\"value\":\"ec2\"}]}},{\"key\":\"aws:Resource\",\"values\":{\"items\":[{\"value\":\"role/EC2_instance_Profile_role\"}]}}, {\"key\":\"iam:RoleName\",\"values\":{\"items\":[{\"value\":\"EC2_instance_Profile_role\"}]}},{\"key\":\"aws:Account\",\"values\":{\"items\":[{\"value\":\"accountID\"}]}}, {\"key\":\"aws:Type\",\"values\":{\"items\":[{\"value\":\"role\"}]}},{\"key\":\"aws:ARN\",\"values\":{\"items\":[{\"value\":\"arn:aws:iam::accountID:role/EC2_instance_Profile_role\"}]}}]}}}"
}


감사합니다.

ªÀº±Û Àϼö·Ï ½ÅÁßÇÏ°Ô.
°­¹ÎÁØ1 2023-03
JSON¾È¿¡ JSONÀÌ ÀÖ´Â ÇüŶó¼­, DecodedMessage ¾È¿¡ ÀÖ´Â °ªÀ» jq·Î »©¼Å¾ß ÇÒ µí ½Í½À´Ï´Ù.
     
°­¹ÎÁØ1 2023-03
cat test.txt | jq '[.DecodedMessage | fromjson | .[]]'

ÀÌ·±½ÄÀ¸·Î ¾²½Ã¸é µÉ °Í °°½À´Ï´Ù.
          
¿Í¿ì.. Ä£ÀýÇÑ ´äº¯ °¨»çÇÕ´Ï´Ù.
jq '[.DecodedMessage | fromjson]' test.txt
ÀÌ·¸°Ô ÇÏ´Ï ´©¶ôµÇ´Â°Ô ¾øÀÌ ´Ù ³ª¿À´Â°Í °°³×¿ä.

ÀÌ·¸°Ô ±îÁö¸¸ Çϼŵµ Á¦°¡ ½áµå¸° À§ Ä¿¸ÇµåÇÏ°í °á°ú´Â µ¿ÀÏÇÕ´Ï´Ù.
cat test.txt | jq '[.DecodedMessage | fromjson ]'


QnA
Á¦¸ñPage 456/5679
2015-12   1478927   ¹é¸Þ°¡
2014-05   4942117   Á¤ÀºÁØ1
2021-07   1924   VSPress
2021-10   1924   ºñºñBB
2023-12   1924   Psychophysi¡¦
2021-05   1924   ºí·¢ÆÞ
2021-10   1924   ÁÖŹé
2023-04   1924   ÇູÇϼ¼
2023-01   1924   ±èÁØÀ¯
2023-02   1924   ¸·¿ï¾ú¾î¿ä
2023-09   1924   ¸Å´Ï¾Æ1
2019-04   1924   ÇູÇϼ¼
2022-10   1925   À¯È£ÁØ
2020-09   1925   pu4ro
2022-05   1925   ¸í±âÅõ¾Ë¶óƾ
2021-05   1925   INMD
2023-04   1925   µÎ¸®¾È
2022-12   1925   cncn
2022-11   1925   PWneo
2022-09   1925   À̹ο쿡¿ä
2023-08   1926   JJAMTIGER
2022-08   1926   ´ÙÇÔ²²½Î´Ù±¸