Jump to content

parse out ticket number


gcue
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • Moderators

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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