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

   Á¶È¸ 1925   Ãßõ 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 439/5678
2014-05   4941459   Á¤ÀºÁØ1
2015-12   1478291   ¹é¸Þ°¡
2023-09   1884   ³×ÀÌÃÄ
2022-05   1884   VSPress
2020-01   1884   NiteFlite9
2023-01   1884   iwill
2023-08   1884   ¼º±â»ç
2023-04   1885   AplPEC
2021-11   1885   galaxyfamily
2023-03   1885   ±×¸°
2021-09   1885   Æ®´Ï¾Æºü
2021-12   1885   ±¸Â÷´Ï
2022-04   1885   ·ÕŸÀÌÁî
2023-03   1886   inquisitive
2023-07   1886   ½Ãµµ´Ï
2021-12   1886   ¹ÌÄ£°¨ÀÚ
2022-08   1886   epowergate
2021-12   1886   isaiah
2021-02   1886   »ßµ¹À̽½ÇÄÀÌ
2022-01   1887   Àü¼³¼ÓÀǹ̡¦
02-08   1887   ¸®¿À
2023-06   1887   ¹Ì´ã