Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cell array incorrectly coercing strings to numbers in JSON output #159

Open
stuffisthings opened this issue Aug 7, 2023 · 0 comments
Open
Labels

Comments

@stuffisthings
Copy link

Describe the bug
I have array cells in my document that can contain a mix of values like 6 or "6-7". I want the numbers to be treated as numbers and the others to be treated as strings. But values like "6-7" are coerced to 6 in the output. This is true even in arrays that are all string values like "6-7"/"6-7"/"6-7" (/ is my seperator here).

To Reproduce
Steps to reproduce the behavior:

  1. Create a cell with value "6-7"/"6-7"/"6-7"
  2. Name the column JA_foo
  3. Options: Array prefix: "JA_", Array seperator: "/", Export contents as array
  4. JSON output will be rendered as [ { "foo": [ 6, 6, 6 ] } ]

Expected behavior
JSON output sould be [ { "foo": [ "6-7", "6-7", "6-7" ] } ]

Screenshots

Here's some test cases against the actual output:
image

[
  {
    "foo": [
      6,
      6,
      6,
      6
    ]
  },
  {
    "foo": [
      "Thing",
      "Thing",
      "Thing"
    ]
  },
  {
    "foo": [
      "One-2",
      "One-3"
    ]
  },
  {
    "foo": [
      "2-One",
      "3-One"
    ]
  },
  {
    "foo": [
      6,
      9
    ]
  },
  {
    "foo": [
      6,
      6,
      6
    ]
  }
]

Info (please complete the following information):

  • Browser: Chrome
  • Do you have multiple accounts signed in? No

Possible solution

My guess would be it has something to do with use of parseFloat in getCellContentArray (because parseFloat('6-7') === 6).

I could try to do a PR at some point but what I've done to deal with similar situations in the past is check the length of parseFloat(val) against the length of val and if they are different treat val as a string -- not sure that is totally robust though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant