Skip to main content

When using a JSON Parser to parse the output from a Web Request, the following JSON is producing the error “Enter a valid JSON payload”. This happens when I try to click the “Generate Output” option.

p{"slot_id":"1791","kiosk_id":"Denver","cabinet_id":"1"},{"slot_id":"1790","kiosk_id":"Denver","cabinet_id":"1"}]

When manually entering in JSON Path expression like “$.0].slot_id”, which should result in “1791”, the result is instead empty.

Hello @jkampman 

Hope you are well,

The Payload provided looks to be in a Array of Json, A Json object would be this alone:

{"slot_id":"1791","kiosk_id":"Denver","cabinet_id":"1"}. So if you’d like to get the data of the Slot_id under the array of Json, You could try something like $.0].0].slot_id and it should get you the data.

 

Hope this helps! Thanks!

Let me know incase of queries! 

 


stike that reading the above, I’m an idiot.

 

Ammar, would this work for grabbing an email from the quoted array:

$.>0][0].email

 

>{"id":"redacted","status":"ACTIVE","created":"2022-08-02T23:24:32.000Z","activated":null,"statusChanged":"2022-08-02T23:28:19.000Z","lastLogin":"2023-03-17T17:11:38.000Z","lastUpdated":"2022-08-02T23:28:19.000Z","passwordChanged":"2022-08-02T23:28:19.000Z","type":{"id":"redacted"},"profile":{"firstName":"redacted","lastName":"redacted","mobilePhone":null,"secondEmail":null,"login":"redacted@redacted.com","email":"redacted@redacted.com"},"credentials":{"password":{},"provider":{"type":"OKTA","name":"OKTA"}},"_links":{"self":{"href":"https://redacted.okta.com/api/v1/users/redacted"}}}]
 


Also, where am I placing ‘$.$0]00].email’ in the web request, expression builder or in the JSON Parser somewhere?


@Ammar KB sorry forgot to tag you!


Hi @Brendan_08 

No worries!

You’d be adding this in the JSON parser itself, Please find an example below:

 

This would be shown in “insert Placeholders” -->Parser fields:

 

Hope this helps!


@Ammar KB like this:

 

 

 


@Brendan_08 Yes, That’s right, But we would be breaking down Array-based elements, For instance if you consider my earlier picture of Json parser, I’m breaking an Array of Strings of conversations from a ticket and taking in the 1st conversation alone by adding d0] to the new element to get the first value:

 

Similarly what you have is an Array of Json objects and hence you’d have to make it 2-dimensional, where the first e0] would be the first array out of 2 arrays and 2nd a0] would be the first element of the first array.

 

Apologies for not elaborating this in earlier replies. Hope this helps! Feel free to reach out to us at support@freshservice.com too for more queries!😄


Yeah, I have a ticket open with support, but they said:

“Hi Brendan,

I think the product team needs to consider this use case and build this natively so that it takes an array into consideration and does not throw an error.

I will keep you posted with more updates on this. Thanks! “

 

So I’m not sure they will be much help.


Apologies, I missed out your earlier reply:

 

In this case, You need not have 0]]0].email, Since you’ve already generated the output for this whole Array, You can simply use insert Placeholders to print the value. That should work


This is the actual response I get from Okta:

 

>{"id":"redacted","status":"ACTIVE","created":"2022-08-02T23:24:32.000Z","activated":null,"statusChanged":"2022-08-02T23:28:19.000Z","lastLogin":"2023-03-17T17:11:38.000Z","lastUpdated":"2022-08-02T23:28:19.000Z","passwordChanged":"2022-08-02T23:28:19.000Z","type":{"id":"redacted"},"profile":{"firstName":"redacted","lastName":"redacted","mobilePhone":null,"secondEmail":null,"login":"redacted@redacted.com","email":"redacted@redacted.com"},"credentials":{"password":{},"provider":{"type":"OKTA","name":"OKTA"}},"_links":{"self":{"href":"https://redacted.okta.com/api/v1/users/redacted"}}}]

 

So that Is what I was trying to get piped into a condition node, and this is the error I am getting, retrieved from the Execution Logs:

 

System Message
tmissing "en.js_translations.execution_logs.webrequest.response_body_new" translation]


{"id":"redacted","status":"ACTIVE","created":"2022-08-02T23:24:32.000Z","activated":null,"statusChanged":"2022-08-02T23:28:19.000Z","lastLogin":"2023-03-17T17:11:38.000Z","lastUpdated":"2022-08-02T23:28:19.000Z","passwordChanged":"2022-08-02T23:28:19.000Z","type":{"id":"redacted"},"profile":{"firstName":"redacted","lastName":"redacted","mobilePhone":null,"secondEmail":null,"login":"redacted@redacted.com","email":"redacted@redacted.com"},"credentials":{"password":{},"provider":{"type":"OKTA","name":"OKTA"}},"_links":{"self":{"href":"https://redacted.okta.com/api/v1/users/redacted"}}}]

 

so should this work, see attached.

 

If not I’ll see if anyone in the community can help me with this, I don’t think support will be much help. Also I guess I should learn about this stuff in general.

 

Thank you for your help!


Reply