Skip to content

Copy tables as JSON objects #100

@wheelercj

Description

@wheelercj

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
  • {"a": ["d", "g"], "b": ["e", "h"], "c": ["f", "i"]} (columns)
  • {"a": ["b", "c"], "d": ["e", "f"], "g": ["h", "i"]} (rows)
  • other
  1. What JSON options should appear in the right-click menu?
  • Only Copy JSON of table, which creates a 2D array unless the table has a header row (created with <th> elements) and/or a header column, in which case the option creates an object. If there is both a header row and a header column, the header row is used as the property names.
  • Both Copy JSON arrays of table and Copy JSON object of table. The object option looks for a header row or header column for the property names, preferring a header row and using the top row if there are no <th> elements.
  • All of Copy JSON arrays of table, Copy JSON columns object of table, and Copy JSON rows object of table. Whether there are <th> elements does not matter.
  • other

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions