Search code examples
javascriptjsonreactjsstringify

JSON.Stringify | Output the result on the screen with quote tags ''


I am using the following methods in my React App to transform my Object to string. Everything works fine, but I want to output the result on the screen without "" around the output.

  renderConfigInfoCellRow = configInfoKey => {
    const { lconfigInfo } = this.props;
    return (
      <tr key={configInfoKey}>
        <td className="pt-3 text-muted font-weight-bold w-25">{configInfoKey}</td>
        {(typeof lconfigInfo.sql[configInfoKey] === 'string' && (
          <td className="pt-3">{JSON.stringify(lconfigInfo.sql[configInfoKey])}</td>
        )}
      </tr>
    );
  };

And I am using it here:

<tbody>
  {Object.keys(lconfigInfo.sql).map(configInfoKey =>
    this.renderConfigInfoCellRow(configInfoKey)
  )}
</tbody>

Any idea of how to remove the "" surrounding the "output" ?? Or if they is an alternative to JSON.Stringify. Thank you!!


Solution

  • There is no sense to use JSON.stringify(), if data is not object, try to change this JSON.stringify(lconfigInfo.sql[configInfoKey]) to lconfigInfo.sql[configInfoKey].

    Also there is condition where you check does the lconfigInfo.sql[configInfoKey] is string and trying to transform it again to string.