thehyve / react-json-to-table

react-json-to-table
GNU General Public License v3.0
36 stars 28 forks source link

bug: boolean value not displayed. #20

Open laixintao opened 3 years ago

laixintao commented 3 years ago

Hi, I think for boolean value, it is better if display string like "true" / "false". Now just displays nothing.

Amedeo91 commented 3 years ago

Hello, yes this issue is pretty annoying!!! If you give me some hints, I can check for the PR and the potential test coverage.

laixintao commented 3 years ago

I think simply add a ?.toString method will resolve this. Now a call ?.toString() on every values before I feed a json into this component. :)

Amedeo91 commented 3 years ago

Yes, but it would be better if it was the library to do it without having me bother doing it in my code :)

ryjogo commented 2 years ago

annoying workaround:

  let filteredData = Object.fromEntries(Object.entries(data));

  Object.entries(filteredData).forEach(([key, value]) => {
    if (typeof value == 'boolean') {
      filteredData[key] = value.toString();
    }
  });
geekdiv commented 2 years ago

simple hack event your object is nested

const convertJSONBooleanToString = (json) => {
    try {
        const strData = JSON.stringify(json)
            .replaceAll(":true", ':"true"')
            .replaceAll(":false", ':"false"');
        return JSON.parse(strData);
    } catch (err) {
        return json;
    }
};