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

   Á¶È¸ 1923   Ãßõ 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 307/5678
2014-05   4940614   Á¤ÀºÁØ1
2015-12   1477481   ¹é¸Þ°¡
2022-12   1592   Çã¿ì´ë
2022-09   1592   ±ä¸Ó¸®·çÀ̽º
2021-11   1592   ¼úÀÌ
07-10   1592   ½Öcpu
2022-03   1592   ³×Æ®¿öÅ©¾î¡¦
2023-03   1592   eu4you
03-05   1592   ¹Ì´ã
02-07   1592   Á¤ÀºÁØ1
05-05   1593   ¼ÒÀÌÄ¡·Î
07-19   1593   ¹¹µçÆȾƿä
2022-06   1593   ¹ÙÄï
2023-05   1593   ÄÚ°ü
01-19   1593   ¹Ì´ã
07-07   1593   ¹Ì´ã
2022-10   1593   2cpumem
2022-06   1593   À嵿°Ç2014
03-13   1594   ¸¶½ºÄÚÆ®
2023-06   1594   Æ縯
04-22   1594   ½º¹«ÇÁ
2023-03   1594   2CPUÃÖÁÖÈñ