Stardown-app / Stardown

Copy the web as markdown
Apache License 2.0
29 stars 1 forks source link

Copy tables as JSON objects #100

Closed wheelercj closed 3 months ago

wheelercj commented 3 months ago

Stardown's latest commits already support copying tables as 2D JSON arrays, but sometimes it might be more helpful to copy tables as JSON objects instead.

However, there are several formats possible. I'm not sure which one(s) to add support for yet and would like feedback from others.

  1. For the table below, which of the following JSON format(s) should Stardown be able to create?
a b c
d e f
g h i
  1. What JSON options should appear in the right-click menu?

Note that some tables have cells that span multiple rows, such as this one: HTML table advanced features and accessibility - Learn web development | MDN. That table also has multiple header rows and multiple header columns.

  1. JSON objects must not have duplicate property names, so some duplicate table cells will need to be made unique somehow. When Stardown is about to create a duplicate property name, should it just append (1), or whatever the next unique number is, to its contents?

For example:

a a a b
c d e f

{"a": ["c"], "a (1)": ["d"], "a (2)": ["e"], "b": ["f"]}

  1. Note that since JSON property names must be strings, some data that normally would not be quoted will need to be quoted. For example:
59 true
35 false
11 true orange

{"59": [35, 11], "true": [false, true], "null": [null, "orange"]}

related

wheelercj commented 3 months ago

We decided to use one simple format for all JSON output.

a b c
d e f
g h i

[{"a": ["b", "c"]}, {"d": ["e", "f"]}, {"g": ["h", "i"]}]

This will replace the current array of arrays format and be the only format for JSON output for the time being. It solves the problem of duplicate property names without changing any property names and makes the data easy to work with in the way it is most commonly used: iterating through the elements in each row. A new setting will be added to the options page: "Empty table cells are converted to ___ in JSON" (a text input field that defaults to null).

More JSON format options may be added in the future.