uzimaru0000/tv

Error: unsupported format

Closed this issue · 5 comments

Caused by:

invalid type: map, expected a sequence at line 1 column 0

Suspicious reason

It seems to happen when returned JSON has no line breaks.

Experiments

According to Your page

The sample API provided in your article on Zenn

curl -s https://jsonplaceholder.typicode.com/users

[
  {
    "id": 1,
    "name": "Leanne Graham",
    "username": "Bret",
    "email": "Sincere@april.biz",
    "address": {
      "street": "Kulas Light",
      "suite": "Apt. 556",
      "city": "Gwenborough",
      "zipcode": "92998-3874",
      "geo": {
        "lat": "-37.3159",
        "lng": "81.1496"
      }
    },
    "phone": "1-770-736-8031 x56442",
    "website": "hildegard.org",
    "company": {
      "name": "Romaguera-Crona",
      "catchPhrase": "Multi-layered client-server neural-net",
      "bs": "harness real-time e-markets"
    }
  },
  {
    "id": 2,
    "name": "Ervin Howell",
    "username": "Antonette",
    "email": "Shanna@melissa.tv",
    "address": {
      "street": "Victor Plains",
      "suite": "Suite 879",
      "city": "Wisokyburgh",
      "zipcode": "90566-7771",
      "geo": {
        "lat": "-43.9509",
        "lng": "-34.4618"
      }
    },
    "phone": "010-692-6593 x09125",
    "website": "anastasia.net",
    "company": {
      "name": "Deckow-Crist",
      "catchPhrase": "Proactive didactic contingency",
      "bs": "synergize scalable supply-chains"
    }
  },
  {
    "id": 3,
    "name": "Clementine Bauch",
    "username": "Samantha",
    "email": "Nathan@yesenia.net",
    "address": {
      "street": "Douglas Extension",
      "suite": "Suite 847",
      "city": "McKenziehaven",
      "zipcode": "59590-4157",
      "geo": {
        "lat": "-68.6102",
        "lng": "-47.0653"
      }
    },
    "phone": "1-463-123-4447",
    "website": "ramiro.info",
    "company": {
      "name": "Romaguera-Jacobson",
      "catchPhrase": "Face to face bifurcated interface",
      "bs": "e-enable strategic applications"
    }
  },
  {
    "id": 4,
    "name": "Patricia Lebsack",
    "username": "Karianne",
    "email": "Julianne.OConner@kory.org",
    "address": {
      "street": "Hoeger Mall",
      "suite": "Apt. 692",
      "city": "South Elvis",
      "zipcode": "53919-4257",
      "geo": {
        "lat": "29.4572",
        "lng": "-164.2990"
      }
    },
    "phone": "493-170-9623 x156",
    "website": "kale.biz",
    "company": {
      "name": "Robel-Corkery",
      "catchPhrase": "Multi-tiered zero tolerance productivity",
      "bs": "transition cutting-edge web services"
    }
  },
  {
    "id": 5,
    "name": "Chelsey Dietrich",
    "username": "Kamren",
    "email": "Lucio_Hettinger@annie.ca",
    "address": {
      "street": "Skiles Walks",
      "suite": "Suite 351",
      "city": "Roscoeview",
      "zipcode": "33263",
      "geo": {
        "lat": "-31.8129",
        "lng": "62.5342"
      }
    },
    "phone": "(254)954-1289",
    "website": "demarco.info",
    "company": {
      "name": "Keebler LLC",
      "catchPhrase": "User-centric fault-tolerant solution",
      "bs": "revolutionize end-to-end systems"
    }
  },
  {
    "id": 6,
    "name": "Mrs. Dennis Schulist",
    "username": "Leopoldo_Corkery",
    "email": "Karley_Dach@jasper.info",
    "address": {
      "street": "Norberto Crossing",
      "suite": "Apt. 950",
      "city": "South Christy",
      "zipcode": "23505-1337",
      "geo": {
        "lat": "-71.4197",
        "lng": "71.7478"
      }
    },
    "phone": "1-477-935-8478 x6430",
    "website": "ola.org",
    "company": {
      "name": "Considine-Lockman",
      "catchPhrase": "Synchronised bottom-line interface",
      "bs": "e-enable innovative applications"
    }
  },
  {
    "id": 7,
    "name": "Kurtis Weissnat",
    "username": "Elwyn.Skiles",
    "email": "Telly.Hoeger@billy.biz",
    "address": {
      "street": "Rex Trail",
      "suite": "Suite 280",
      "city": "Howemouth",
      "zipcode": "58804-1099",
      "geo": {
        "lat": "24.8918",
        "lng": "21.8984"
      }
    },
    "phone": "210.067.6132",
    "website": "elvis.io",
    "company": {
      "name": "Johns Group",
      "catchPhrase": "Configurable multimedia task-force",
      "bs": "generate enterprise e-tailers"
    }
  },
  {
    "id": 8,
    "name": "Nicholas Runolfsdottir V",
    "username": "Maxime_Nienow",
    "email": "Sherwood@rosamond.me",
    "address": {
      "street": "Ellsworth Summit",
      "suite": "Suite 729",
      "city": "Aliyaview",
      "zipcode": "45169",
      "geo": {
        "lat": "-14.3990",
        "lng": "-120.7677"
      }
    },
    "phone": "586.493.6943 x140",
    "website": "jacynthe.com",
    "company": {
      "name": "Abernathy Group",
      "catchPhrase": "Implemented secondary concept",
      "bs": "e-enable extensible e-tailers"
    }
  },
  {
    "id": 9,
    "name": "Glenna Reichert",
    "username": "Delphine",
    "email": "Chaim_McDermott@dana.io",
    "address": {
      "street": "Dayna Park",
      "suite": "Suite 449",
      "city": "Bartholomebury",
      "zipcode": "76495-3109",
      "geo": {
        "lat": "24.6463",
        "lng": "-168.8889"
      }
    },
    "phone": "(775)976-6794 x41206",
    "website": "conrad.com",
    "company": {
      "name": "Yost and Sons",
      "catchPhrase": "Switchable contextually-based project",
      "bs": "aggregate real-time technologies"
    }
  },
  {
    "id": 10,
    "name": "Clementina DuBuque",
    "username": "Moriah.Stanton",
    "email": "Rey.Padberg@karina.biz",
    "address": {
      "street": "Kattie Turnpike",
      "suite": "Suite 198",
      "city": "Lebsackbury",
      "zipcode": "31428-2261",
      "geo": {
        "lat": "-38.2386",
        "lng": "57.2232"
      }
    },
    "phone": "024-648-3804",
    "website": "ambrose.net",
    "company": {
      "name": "Hoeger LLC",
      "catchPhrase": "Centralized empowering task-force",
      "bs": "target end-to-end models"
    }
  }
]%

curl -s https://jsonplaceholder.typicode.com/users | tv

+--+------------------------+----------------+-------------------------+-------+---------------------+-------------+-------+
|id|name |username |email |address|phone |website |company|
+--+------------------------+----------------+-------------------------+-------+---------------------+-------------+-------+
|1 |Leanne Graham |Bret |Sincere@april.biz |... |1-770-736-8031 x56442|hildegard.org|... |
|2 |Ervin Howell |Antonette |Shanna@melissa.tv |... |010-692-6593 x09125 |anastasia.net|... |
|3 |Clementine Bauch |Samantha |Nathan@yesenia.net |... |1-463-123-4447 |ramiro.info |... |
|4 |Patricia Lebsack |Karianne |Julianne.OConner@kory.org|... |493-170-9623 x156 |kale.biz |... |
|5 |Chelsey Dietrich |Kamren |Lucio_Hettinger@annie.ca |... |(254)954-1289 |demarco.info |... |
|6 |Mrs. Dennis Schulist |Leopoldo_Corkery|Karley_Dach@jasper.info |... |1-477-935-8478 x6430 |ola.org |... |
|7 |Kurtis Weissnat |Elwyn.Skiles |Telly.Hoeger@billy.biz |... |210.067.6132 |elvis.io |... |
|8 |Nicholas Runolfsdottir V|Maxime_Nienow |Sherwood@rosamond.me |... |586.493.6943 x140 |jacynthe.com |... |
|9 |Glenna Reichert |Delphine |Chaim_McDermott@dana.io |... |(775)976-6794 x41206 |conrad.com |... |
|10|Clementina DuBuque |Moriah.Stanton |Rey.Padberg@karina.biz |... |024-648-3804 |ambrose.net |... |
+--+------------------------+----------------+-------------------------+-------+---------------------+-------------+-------+

My target

When getting JSON from my target, Hymnary

curl "https://hymnary.org/api/scripture?book=Genesis&fromChapter=3&fromVerse=1&toChapter=3&toVerse=24"

curl "curl "https://hymnary.org/api/scripture?book=Genesis&fromChapter=3&fromVerse=1&toChapter=3&toVerse=24"
{"Break forth, O beauteous heavenly light":{"title":"Break Forth, O Beauteous Heavenly Light","meter":"8 7 8 7 8 8 7 7","text link":"https:\/\/hymnary.org\/text\/break_forth_o_beauteous_heavenly_light","number of hymnals":"53","scripture references":"Genesis 3:15;  Genesis 3:8-15","author":"Rist, Johann, 1607-1667","translator":"Troutbeck, J. (John), 1832-1899"},"Christ the Victorious, give to your servants":{"title":"Christ the Victorious, Give to Your Servants","meter":"11 10. 11 9","text link":"https:\/\/hymnary.org\/text\/christ_the_victorious_give_to_your_serva","number of hymnals":"10","scripture references":"Genesis 3:19","author":"Daw, Carl P. Jr., 1944-"},"How sweet was the garden, fertile and fair":{"title":"How Sweet Was the Garden, Fertile and Fair","meter":"10.10.11.11","text link":"https:\/\/hymnary.org\/text\/how_sweet_was_the_garden_fertile_and_fai","number of hymnals":"1","scripture references":"Genesis 3:1-19;  Genesis 2:8 - 3:1","author":"Daw, Carl P. Jr., 1944-"},"I come to the garden alone":{"title":"In the Garden","meter":"8.9.10.7 with refrain","text link":"https:\/\/hymnary.org\/text\/i_come_to_the_garden_alone","number of hymnals":"237","scripture references":"Genesis 3:8","author":"Miles, C. Austin (Charles Austin), 1868-1946"},"Joy to the world! the Lord is come!":{"title":"Joy to the world! the Lord is come!","meter":"8.6.8.6.","text link":"https:\/\/hymnary.org\/text\/joy_to_the_world_the_lord_is_come","number of hymnals":"1752","scripture references":"Genesis 3:17-19;  Genesis 3:17-18","author":"Watts, Isaac, 1674-1748"},"O Christ, the healer, we have come":{"title":"O Christ, the Healer","meter":"LM","text link":"https:\/\/hymnary.org\/text\/o_christ_the_healer_we_have_come","number of hymnals":"35","scripture references":"Genesis 3:17-19","author":"Green, Fred Pratt, 1903-2000"},"Praise the Savior Now and ever (Wallin)":{"title":"Praise the Savior","meter":"4 4 7 4 4 7 4 4 7","text link":"https:\/\/hymnary.org\/text\/praise_the_savior_now_and_ever_wallin","number of hymnals":"20","scripture references":"Genesis 3:15","author":"Fortunatus, Venantius Honorius Clementianus, ca. 540-ca. 600","translator":"Wallin, Johan Olof, 1779-1839"},"Sing, choirs of new Jerusalem":{"title":"Sing, Choirs of New Jerusalem","meter":"8.6.8.6. with repeats","original language":"Latin","text link":"https:\/\/hymnary.org\/text\/sing_choirs_of_new_jerusalem","number of hymnals":"61","scripture references":"Genesis 3:15","author":"Fulbert, Saint, Bishop of Chartres, ca 960-1028","translator":"Campbell, Robert, 1814-1868"},"Sing, my tongue, the Savior's glory, Tell his triumph far and wide":{"title":"Sing, my tongue, the Saviour's battle","meter":"8.7.8.7.8.7.","text link":"https:\/\/hymnary.org\/text\/sing_my_tongue_the_saviors_glory_tell_hi","number of hymnals":"41","scripture references":"Genesis 3:6","translator":"Caswall, Edward, 1814-1878","author":"Fortunatus, Venantius Honorius Clementianus, ca. 540-ca. 600"},"Surely, you alone can save us":{"title":"Sign Us with Ashes","date":"2013","meter":"LM with refrain","text link":"https:\/\/hymnary.org\/text\/surely_you_alone_can_save_us","number of hymnals":"5","scripture references":"Genesis 3:19","author":"Bringle, Mary Louise, 1953-"},"There in God's garden stands the Tree of Wisdom":{"title":"There in God's Garden","meter":"11 11 11 5","text link":"https:\/\/hymnary.org\/text\/there_in_gods_garden_stands_the_tree_of","number of hymnals":"14","scripture references":"Genesis 3:7","author":"von P\u00e9cselyi, Kir\u00e1ly Imre, c.1590-c.1641","translator":"Routley, Erik, 1917-1982"},"This is my Father's world And to my listening ears":{"title":"This Is My Father's World","meter":"6.6.8.6. D.","text link":"https:\/\/hymnary.org\/text\/this_is_my_fathers_world_and_to_my","number of hymnals":"294","scripture references":"Genesis 3;  Genesis 3:8-15","author":"Babcock, Maltbie D. (Maltbie Davenport), 1858-1901"},"What Adam's disobedience cost":{"title":"What Adam's Disobedience Cost","meter":"8.6.7.6.6","text link":"https:\/\/hymnary.org\/text\/what_adams_disobedience_cost","number of hymnals":"6","scripture references":"Genesis 3:1-8;  Genesis 3:14-24","author":"Green, Fred Pratt, 1903-2000"}}%
[masarukitajima@localhost /Users/masarukitajima:] $ curl "https://hymnary.org/api/scripture?book=Genesis&fromChapter=3&fromVerse=1&toChapter=3&toVerse=24"

{"Break forth, O beauteous heavenly light":{"title":"Break Forth, O Beauteous Heavenly Light","meter":"8 7 8 7 8 8 7 7","text link":"https:\/\/hymnary.org\/text\/break_forth_o_beauteous_heavenly_light","number of hymnals":"53","scripture references":"Genesis 3:15;  Genesis 3:8-15","author":"Rist, Johann, 1607-1667","translator":"Troutbeck, J. (John), 1832-1899"},"Christ the Victorious, give to your servants":{"title":"Christ the Victorious, Give to Your Servants","meter":"11 10. 11 9","text link":"https:\/\/hymnary.org\/text\/christ_the_victorious_give_to_your_serva","number of hymnals":"10","scripture references":"Genesis 3:19","author":"Daw, Carl P. Jr., 1944-"},"How sweet was the garden, fertile and fair":{"title":"How Sweet Was the Garden, Fertile and Fair","meter":"10.10.11.11","text link":"https:\/\/hymnary.org\/text\/how_sweet_was_the_garden_fertile_and_fai","number of hymnals":"1","scripture references":"Genesis 3:1-19;  Genesis 2:8 - 3:1","author":"Daw, Carl P. Jr., 1944-"},"I come to the garden alone":{"title":"In the Garden","meter":"8.9.10.7 with refrain","text link":"https:\/\/hymnary.org\/text\/i_come_to_the_garden_alone","number of hymnals":"237","scripture references":"Genesis 3:8","author":"Miles, C. Austin (Charles Austin), 1868-1946"},"Joy to the world! the Lord is come!":{"title":"Joy to the world! the Lord is come!","meter":"8.6.8.6.","text link":"https:\/\/hymnary.org\/text\/joy_to_the_world_the_lord_is_come","number of hymnals":"1752","scripture references":"Genesis 3:17-19;  Genesis 3:17-18","author":"Watts, Isaac, 1674-1748"},"O Christ, the healer, we have come":{"title":"O Christ, the Healer","meter":"LM","text link":"https:\/\/hymnary.org\/text\/o_christ_the_healer_we_have_come","number of hymnals":"35","scripture references":"Genesis 3:17-19","author":"Green, Fred Pratt, 1903-2000"},"Praise the Savior Now and ever (Wallin)":{"title":"Praise the Savior","meter":"4 4 7 4 4 7 4 4 7","text link":"https:\/\/hymnary.org\/text\/praise_the_savior_now_and_ever_wallin","number of hymnals":"20","scripture references":"Genesis 3:15","author":"Fortunatus, Venantius Honorius Clementianus, ca. 540-ca. 600","translator":"Wallin, Johan Olof, 1779-1839"},"Sing, choirs of new Jerusalem":{"title":"Sing, Choirs of New Jerusalem","meter":"8.6.8.6. with repeats","original language":"Latin","text link":"https:\/\/hymnary.org\/text\/sing_choirs_of_new_jerusalem","number of hymnals":"61","scripture references":"Genesis 3:15","author":"Fulbert, Saint, Bishop of Chartres, ca 960-1028","translator":"Campbell, Robert, 1814-1868"},"Sing, my tongue, the Savior's glory, Tell his triumph far and wide":{"title":"Sing, my tongue, the Saviour's battle","meter":"8.7.8.7.8.7.","text link":"https:\/\/hymnary.org\/text\/sing_my_tongue_the_saviors_glory_tell_hi","number of hymnals":"41","scripture references":"Genesis 3:6","translator":"Caswall, Edward, 1814-1878","author":"Fortunatus, Venantius Honorius Clementianus, ca. 540-ca. 600"},"Surely, you alone can save us":{"title":"Sign Us with Ashes","date":"2013","meter":"LM with refrain","text link":"https:\/\/hymnary.org\/text\/surely_you_alone_can_save_us","number of hymnals":"5","scripture references":"Genesis 3:19","author":"Bringle, Mary Louise, 1953-"},"There in God's garden stands the Tree of Wisdom":{"title":"There in God's Garden","meter":"11 11 11 5","text link":"https:\/\/hymnary.org\/text\/there_in_gods_garden_stands_the_tree_of","number of hymnals":"14","scripture references":"Genesis 3:7","author":"von P\u00e9cselyi, Kir\u00e1ly Imre, c.1590-c.1641","translator":"Routley, Erik, 1917-1982"},"This is my Father's world And to my listening ears":{"title":"This Is My Father's World","meter":"6.6.8.6. D.","text link":"https:\/\/hymnary.org\/text\/this_is_my_fathers_world_and_to_my","number of hymnals":"294","scripture references":"Genesis 3;  Genesis 3:8-15","author":"Babcock, Maltbie D. (Maltbie Davenport), 1858-1901"},"What Adam's disobedience cost":{"title":"What Adam's Disobedience Cost","meter":"8.6.7.6.6","text link":"https:\/\/hymnary.org\/text\/what_adams_disobedience_cost","number of hymnals":"6","scripture references":"Genesis 3:1-8;  Genesis 3:14-24","author":"Green, Fred Pratt, 1903-2000"}}%

curl -s "https://hymnary.org/api/scripture?book=Genesis&fromChapter=3&fromVerse=1&toChapter=3&toVerse=24" | tv -r

Error: unsupported format

Caused by:
    invalid type: map, expected a sequence at line 1 column 0

Thank you for your report.
However, this format was unexpected.
What about commands like the following?

curl -s "https://hymnary.org/api/scripture?book=Genesis&fromChapter=3&fromVerse=1&toChapter=3&toVerse=24" \
  | jq "[.]" \
  | tv -r

In this state, it is not a single table, so you can use the following command:

$ curl -s "https://hymnary.org/api/scripture?book=Genesis&fromChapter=3&fromVerse=1&toChapter=3&toVerse=24" \
  | jq "to_entries | [.[] | {key} + .value ]" \
  | tv

@uzimaru0000
Thank you for your quick response and suggestions.
But, I wonder what do you mean by

However, this format was unexpected.

This format is a valid format according to RFC 8259.

I'm sorry that I'm not familiar with jq, and I think that the importance of studying jq is not high.
jq is a kind of a lightweight and flexible command-line JSON processor.

Since this CLI is a Format json into table view, using another formatter as a preprocessor means this CLI can't format correctly.

Please do not misunderstand. I'm not blaming or any aggressive actions. Truly, I evaluate this CLI is so good. If I don't think so, I wouldn't raise an issue.

Conclusion

What I want to say can be summarized to the following.

A formatting tool for a specific language is required to handle every format that is defined in the language's official document.

Suggestion

It is a good idea to create a table, but regarding current situations of the IT industry, the Markdown table format will be appreciated.

It means that the format as JSON is satisfied, but not as the format required by this CLI.
If you have a specific idea or implementation, I might incorporate it if you create a PR.

Hi,

@uzimaru0000 ,

It means that the format as JSON is satisfied, but not as the format required by this CLI.

If that's the case, it is necessary to specify tv's requirements about the acceptable format.

Currently, it's not written and the title is “Format json into table view.” Also, it is necessary to read your README by yourself from a point of view of someone who visited this repository for the first time.

Then you will find that tv seems to accept all JSON files that satisfy RFC 8259.

But, as an IT engineer with 33 years of experience, writing tv's requirements about the acceptable format means creating an escape route.

If the tv is a formatting tool that shows a JSON file in a Table format, it is the developer's responsibility to handle JSON files in any valid format.

If you have a specific idea or implementation, I might incorporate it if you create a PR.

Don't ask your app's lack of implements to the one who raised this issue.

If you are a professional engineer as you wrote in Zenn, you may be able to understand what it means. It means that your abdication of responsibility.

I'm not accusing you, but advice from a well-experienced engineer.

This tool is OSS, so if you have suggestions for improvements, create a PR!
I'm looking forward to your contribution with your vast experience!