Hi - does anyone know how to parse the metadata field? It looks like a json field but it is not.
Hi, @abaldinger.
Apologies for the delayed response. My team strives to respond to posts within 48 hours and this one fell through the cracks.
Could you clarify your goal and the issues you’re encountering?
The Engagements API’s metadata field should contain a JSON object. If you are not seeing JSON returned, could you provide an example request and body (please remove any OAuth tokens or API keys)?
Trying to parse the engagements metadata field as json but the postgres function is returning an error.
metadata value = {‘body’: ‘<p>fjhdfjhsdfjsdfjsdfjksdfkj</p>’}
error and sql =
sql> select x.body
from staging.hubspot_engagements
CROSS JOIN LATERAL
json_to_recordset(metadata::json) as x(body text) limit 1
[2019-05-08 07:57:22] [22P02] ERROR: invalid input syntax for type json
[2019-05-08 07:57:22] Detail: Token “'” is invalid.
[2019-05-08 07:57:22] Where: JSON data, line 1: {'…
Hi, @abaldinger.
Are you receiving data in that format from the Engagements API?
If so, can you share a request URL (minus any authentication details) which returns a metadata payload containing single quotes(')?
example 2:
{‘from’: {‘raw’: ‘EmailAddress{name=Christopher Ryan, address=cryan@forecast5analytics.com}’, ‘email’: ‘cryan@forecast5analytics.com’, ‘firstName’: ‘Christopher’, ‘lastName’: ‘Ryan’}, ‘to’: [{‘raw’: ‘EmailAddress{name=Michelle Salazar, address=salazarm@venusisd.net}’, ‘email’: ‘salazarm@venusisd.net’, ‘firstName’: ‘Michelle’, ‘lastName’: ‘Salazar’}], ‘cc’: [], ‘bcc’: [], ‘sender’: {}, ‘subject’: ‘RE: Venus ISD - Forecast5 Analytics’, ‘html’: ‘\n \n \n \n \n \n \n \n Hi Michelle, \n \ \n Good luck with the construction project. \n \ \n Send me a couple of dates that work for you, possibly around the middle of March and I will get a web meeting scheduled. \n \ \n Thanks again! Chris \n \ \n Christopher Ryan \n Sales Account Executive \n \ \n Forecast5 Analytics, Inc. \n 2135 CityGate Lane – 7th Floor \n Naperville, IL 60563 \n \ \n - - - - - - - - - - - - - - - - - \n Office 630 955-7663 \n Cell\ \ \ \ 630 715-1032 \n Forecast5Analytics.com \n \ \n \ \n \n From: Michelle Salazar [mailto:salazarm@venusisd.net] Sent: Thursday, February 2, 2017 8:42 AM To: Christopher Ryan <cryan@forecast5analytics.com> Subject: Re: Venus ISD - Forecast5 Analytics \n \ \n \n Thank you Chris.\ I will get back with you on some dates. \n \n \n \ \n \n On Wed, Feb 1, 2017 at 8:54 PM, Christopher Ryan <cryan@forecast5analytics.com> wrote: \n \n \n \n Good morning Michelle, \n \ \n Thank you for stopping by the booth to visit with us this week. If you are interested in a demo or continuing our discussion, just name some times you are free and I will get a web meeting scheduled. \n \ \n Please find the attached presentation by Tish Grill from Boerne ISD and Emily Bruere from our Forecast5 Analytics team. Tish presented some of the ways she uses the 5Sight platform. \n \ \n Thank you again for making time to see us and I look forward to connecting again this year. \n \ \n Chris \n \ \n Christopher Ryan \n Sales Account Executive \n \ \n Forecast5 Analytics, Inc. \n 2135 CityGate Lane – 7th Floor \n Naperville, IL 60563 \n \ \n - - - - - - - - - - - - - - - - - \n Office 630 955-7663 \n Cell\ \ \ \ 630 715-1032 \n Forecast5Analytics.com \n \ \n \ \n \n \n \n \n \n \n \ \n \n -- \n \n \n \n \n \n \n \n Michelle Salazar \n \n \n Chief Financial Officer \n \n \n Venus ISD \n \n \n Phone 972-366-3448 ext 104 \n \n \n Fax 972-232-2141 \n \n \n \ \n \n \n \ \n \n \n CONFIDENTIALITY NOTICE: This email & any attached documents may contain confidential information.\ \ All information is intended only for the use of the named recipient.\ \ If you are not the named recipient, you are not authorized to read, disclose, copy, distribute or take any action in reliance on the information and any action other than immediate delivery to the named recipient is strictly prohibited.\ \ If you have received this email in error, do not read the information and please immediately notify sender by telephone to arrange for a return of the original documents.\ \ If you are the named recipient you are not authorized to reveal any of this information to any other unauthorized person.\ \ If you did not receive all pages listed or if pages are not legible, please immediately notify sender by phone. \n \n \n \n \n \n \n \n \n \n \n \n’, ‘trackerKey’: ‘eb9526c4-b97a-4ed7-9494-2b0d7eabf823’, ‘messageId’: ‘’, ‘threadId’: ‘5cc5e03f3f99b927478cfd55e71f7dc3’, ‘emailSendEventId’: {}, ‘validationSkipped’: []}
error:
sql> select x.body
from staging.hubspot_engagements
CROSS JOIN LATERAL
json_to_recordset(regexp_replace(metadata, ‘<[^>]*>’, ‘’, ‘g’)::json) as x(body text)
where id = 200947975
[2019-05-09 09:13:56] [22P02] ERROR: invalid input syntax for type json
[2019-05-09 09:13:56] Detail: Token “'” is invalid.
[2019-05-09 09:13:56] Where: JSON data, line 1: {'…
Hi, @abaldinger.
I’m sorry that your reply fell through the cracks. Be sure to tag me with @IsaacTakushi so that I’m notified of future replies.
I see single quotes (') in that payload, but I’m still unsure what endpoint returned it. Per my last message, would you please share a full request URL to the Engagements API (minus any authentication details) so that I can replicate the request?
Hi @IsaacTakushi We have been able to determine the what is being returned by the API is correct. Our python code has to convert the json field to a dictionary and then load it in to postgreSQL. it’s at this point it bc unusable to convert back to JSON due to the quotes and possibly other character issues.
Hi, @abaldinger.
I’m glad you found the root cause! Thanks for sharing this insight on the Community.