Jump to content

Recommended Posts

Posted (edited)

Hello

I am trying to get GMS-600 from this $oHTTP.ResponseText but have not been able to figure out the right syntax.  THANK YOU in advance!

$txt = '{"_expands":["participant","status","sla","requestType","serviceDesk"],"issueId":"1301831","issueKey":"GMS-600","requestTypeId":"300","serviceDeskId":"13","createdDate":{"iso8601":"2021-10-12T07:08:17-0700","jira"}}'

;$ticket = StringRegExpReplace($txt, '"issueKey":[\w]', "")
$ticket = StringRegExpReplace($txt, "issueKey[\w]:", "")
Edited by gcue
  • Moderators
Posted

gcue,

This works for me - and will look for any number of capital letters, a dash, and any number of digits at that position:

$txt = '{"_expands":["participant","status","sla","requestType","serviceDesk"],"issueId":"1301831","issueKey":"GMS-600","requestTypeId":"300","serviceDeskId":"13","createdDate":{"iso8601":"2021-10-12T07:08:17-0700","jira"}}'

$ticket = StringRegExpReplace($txt, '(.*Key":")([A-Z]*-\d*)(",".*)', "$2")

ConsoleWrite($ticket & @CRLF)

It looks for 3 groups: everything up to the end of the "issueKey" section, the section you want, and then all the rest - returning just the second section, which is the one you want.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

Here is version using _StringBetween():

#Include <String.au3>

$txt = '{"_expands":["participant","status","sla","requestType","serviceDesk"],"issueId":"1301831","issueKey":"GMS-600","requestTypeId":"300","serviceDeskId":"13","createdDate":{"iso8601":"2021-10-12T07:08:17-0700","jira"}}'

$ticket = StringBetween($txt, '"issueKey":"', '"')
ConsoleWrite($ticket & @CRLF)

; wrapper to return string instead of array
Func StringBetween($sString, $sStart, $sEnd)
    $sReturn = _StringBetween($sString, $sStart, $sEnd)
    If @error Then Return ''
    Return $sReturn[0]
EndFunc

 

Edited by Zedna
Posted (edited)

this seems to work.  

#include <Array.au3>


$txt = '{"_expands":["participant","status","sla","requestType","serviceDesk"],"issueId":"1301831","issueKey":"GMS-600","requestTypeId":"300","serviceDeskId":"13","createdDate":{"iso8601":"2021-10-12T07:08:17-0700","jira"}}'

$ticket = StringRegExp($txt, "[A-Z]{3}-\d+", 1)

if IsArray($ticket) Then _ArrayDisplay($ticket)

 

Edited by markyrocks
Posted

Kind of surprised that no one has mentioned using a JSON UDF yet. That's the proper way to do it unless you are really sure that you won't need to do anything else with the response.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted (edited)

Use RegEx and forget it, or spend an hour learning Jason JSON parsing? RegEx wins everytime!

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

  Reveal hidden contents

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...