-6

Trying to grab a number from this JSON:

{
   "event":"shipment.status_update",
   "status":"in_transit",
   "updated_at":"2017-12-08T03:29:24.591+00:00",
   "shipment_id":2023431,
   "shid":2023431,
   "shipment_public_id":"shp_tnwr4GjD",
   "order_number":"MF17966",
   "source_system_id":null
}

Need to extract the number after shid. In this case, 2023431.

Edit:

What I'm trying to do is build a Zapier workflow that:

  1. Catches a raw hook
  2. Runs a Javascript that outputs the shid value from above
  3. Then I'm going to use that value to call a webservice
  4. And finally send an email to an individual

I'm able to catch the hook and don't anticipate any trouble with the 3rd and 4th part of the workflow. But capturing that shid is proving troublesome.

So far I've tried using the following in the Code element:

shid = (inputData["shid"]);
output = shid;
  • Why not decode that (it looks like JSON) and address the element instead of brute-forcing a pattern match (which is a very brittle strategy for the type of data you're presenting) – DDeMartini Dec 18 '17 at 16:08
  • I'm voting to close this question as off-topic because the OP is just asking for a solution, sans personal research/effort. – dda Dec 18 '17 at 16:11
  • Didn't get anywhere with RegEx. Trying to extract for a Zapier workflow. – user1257826 Dec 18 '17 at 16:18
  • This can be closed. Should have spent more time with it before posting. – user1257826 Dec 18 '17 at 16:52

1 Answers1

2

You should use json.loads()

import json
output = json.loads(text)
print (output["shid"])

the number will be printed out.

YGouddi
  • 341
  • 2
  • 14