mattn / bsky

A cli application for bluesky social
269 stars 26 forks source link

bsky thread --json returns invalid JSON. #7

Closed hyuki closed 1 year ago

hyuki commented 1 year ago

bsky thread --json at://did:... returns invalid JSON.

Example session is as follows (full session is on gist):

[~] $ go version
go version go1.19.5 darwin/arm64
[~] $ bsky version
No help topic for 'version'
[~] $ bsky -version
bsky version 0.0.31
[~] $ bsky post "This post is for reporting an issue."
at://did:plc:k762js3b44u4kppedx63ozsw/app.bsky.feed.post/3jua2zpthm42n
[~] $ bsky post -r at://did:plc:k762js3b44u4kppedx63ozsw/app.bsky.feed.post/3jua2zpthm42n "This is a reply."
at://did:plc:k762js3b44u4kppedx63ozsw/app.bsky.feed.post/3jua345boc52s
[~] $ bsky thread --json at://did:plc:k762js3b44u4kppedx63ozsw/app.bsky.feed.post/3jua2zpthm42n | jq
{
  "author": {
    ...
  },
  "cid": "bafyreie6ozkcr5sfhcocg34gv7s7ya6vs5os57bo34ih5yqz23xzrvh5gy",
  "indexedAt": "2023-04-25T22:00:12.006Z",
  "likeCount": 0,
  "record": {
    ...
  },
  "replyCount": 1,
  "repostCount": 0,
  "uri": "at://did:plc:k762js3b44u4kppedx63ozsw/app.bsky.feed.post/3jua2zpthm42n",
  "viewer": {}
}
{
  "$type": "app.bsky.feed.defs#threadViewPost",
  "post": {
    "author": {
      ...
    },
    "cid": "bafyreigjf6s3ipgju2irqszouncglj7rzndhtf2kknsxmzgd6qo62eojim",
    "indexedAt": "2023-04-25T22:01:33.191Z",
    "likeCount": 0,
    "record": {
      "$type": "app.bsky.feed.post",
      "createdAt": "2023-04-26T07:01:33+09:00",
      "reply": {
        "parent": {
          "cid": "bafyreie6ozkcr5sfhcocg34gv7s7ya6vs5os57bo34ih5yqz23xzrvh5gy",
          "uri": "at://did:plc:k762js3b44u4kppedx63ozsw/app.bsky.feed.post/3jua2zpthm42n"
        },
        "root": {
          "cid": "bafyreie6ozkcr5sfhcocg34gv7s7ya6vs5os57bo34ih5yqz23xzrvh5gy",
          "uri": "at://did:plc:k762js3b44u4kppedx63ozsw/app.bsky.feed.post/3jua2zpthm42n"
        }
      },
      "text": "This is a reply."
    },
    "replyCount": 0,
    "repostCount": 0,
    "uri": "at://did:plc:k762js3b44u4kppedx63ozsw/app.bsky.feed.post/3jua345boc52s",
    "viewer": {}
  }
}
[~] $

As you can see, bsky thread --json at://did:... returns { ... }{ ... }. It is invalid JSON.

hyuki commented 1 year ago

It looks that bsky thread --json still produces invalid JSON as follows.

$ brew install jsonlint
$ git log --oneline | head -3
cdff7fd thread's JSON should be FeedDefs_ThreadViewPost.Post
50a4a68 bump up version to 0.0.31
f646d1b add -pattern and -reply
$ make all
$ ./bsky thread --json at://did:plc:k762js3b44u4kppedx63ozsw/app.bsky.feed.post/3ju6nl3mnvx22 | jq | jsonlint -c
line 142, col 1, found: '{' - expected: 'EOF', '}', ',', ']'.
$ ./bsky thread --json at://did:plc:k762js3b44u4kppedx63ozsw/app.bsky.feed.post/3ju6nl3mnvx22 | jsonlint -c
line 1, col 4034, found: '{' - expected: 'EOF', '}', ',', ']'.
hyuki commented 1 year ago

I heard that bsky produces ndjson. The separator is "\n". So current behaviour is valid as ndjson. Each line is valid JSON as follows:

$ ./bsky thread --json at://did:plc:k762js3b44u4kppedx63ozsw/app.bsky.feed.post/3ju6nl3mnvx22 | head -1 | jsonlint -c
(No error, displays pretty-printed JSON (for first line of result)