1

I have read a few anwsers on SO but none seem to come across what I need.

I have a function:

const geoDataRTB = () => {
  return data.map((result) => result.request.buyerContext.request.geoData);
};

Which returns a json object.

"geoData": {
                        "type": "GPS",
                        "areaCode": "586",
                        "city": "MACOMB",
                        "country": "USA",
                        "metro": "505",
                        "latitude": "42.311859",
                        "longitude": "-85.579595",
                        "state": "MI",
                        "postalCode": "48042",
                        "bandwidth": "MOBILE",
                        "sic": "517312",
                        "domain": "MYVZW.COM",
                        "cityCode": 0
                    },

For example...currently I am returning geoData.city but id rather return the whole geoDta object instead. The end result is displayed via this

<section id='returnedData' className='mt-5 pb-5'>
        <h2 className={h2Styles}>result</h2>
        <div className='bg-gray-700 text-white rounded-md p-5 mt-5 '>
          {data.map((result, i) => (
            <div className='py-1'>
              <span className='text-xs text-gray-400 font-mono'>Capture {i} : </span>
              <span className='font-mono'>{result}</span>
              <br />
            </div>
          ))}
        </div>
      </section>

But when trying to return the geoData i get the object child error. Any suggestions on how to display the object? I have tried

const geoDataRTB = () => {
  return data.map((result) => result.request.buyerContext.request.geoData.toString());
};

But this just returns [Object, Object]

1
  • 1
    If you want to display result as font-mono's content, you may change your code to: <span className='font-mono'>{JSON.stringify(result)}</span> Commented Jul 2, 2021 at 13:10

2 Answers 2

1

If you want to display JSON as-is, usually you write something like:

<pre>
     {JSON.stringify(OBJECT, null, 2)}
</pre>

That will show a javascript object pretty printed.

Sign up to request clarification or add additional context in comments.

Comments

1

It looks to me like you want to display your data inside your monospace section, and not that you want to pass the data around for further manipulation or styling it in a different way.

If that's the case, you'll need to do:

const geoDataRTB = () => {
  return data.map(result => JSON.stringify(result.request.buyerContext.request.geoData));
};

2 Comments

Nice!! this works...but how could i format this so it looks like JSON? Can i manlipuate the string to look like JSON?
use a <pre> tag

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.