0

I have the below JSON file and I need to extract values from the JSON file and assign it to variables. I need to extract the id and the fromref display id. Any help would be greatly appreciated.

{
"size":  2,
"limit":  25,
"isLastPage":  true,
"values":  [
               {
                   "id":  1857,
                   "version":  7,
                   "title":  "Update schema from excel",
                   "description":  "Running Update schema from excel",
                   "state":  "DECLINED",
                   "open":  false,
                   "closed":  true,
                   "createdDate":  1538081524777,
                   "updatedDate":  1538159225677,
                   "closedDate":  1538159225677,
                   "fromRef":  "@{id=refs/heads/schema/2018.5.63107; displayId=schema/2018.5.63107; latestCommit=39be0e339f87c890f67fa6af426c7d96564eae0b; repository=}",
                   "toRef":  "@{id=refs/heads/develop; displayId=develop; latestCommit=b2bedca4a23e7a2f76fae8201b715edc69aaad23; repository=}",
                   "locked":  false,
                   "author":  "@{user=; role=AUTHOR; approved=False; status=UNAPPROVED}",
                   "reviewers":  "             ",
                   "participants":  "",
                   "properties":  "@{mergeResult=; resolvedTaskCount=0; commentCount=1; openTaskCount=0}",
                   "links":  "@{self=System.Object[]}"
               },
               {
                   "id":  1862,
                   "version":  1,
                   "title":  "Update schema from excel",
                   "description":  "Running Update schema from excel",
                   "state":  "DECLINED",
                   "open":  false,
                   "closed":  true,
                   "createdDate":  1538155196583,
                   "updatedDate":  1538159165303,
                   "closedDate":  1538159165303,
                   "fromRef":  "@{id=refs/heads/schema/2018.7.63125; displayId=schema/2018.7.63125; latestCommit=48e827093ac86a86dff58f5215f0ff558ce9da72; repository=}",
                   "toRef":  "@{id=refs/heads/develop; displayId=develop; latestCommit=b2bedca4a23e7a2f76fae8201b715edc69aaad23; repository=}",
                   "locked":  false,
                   "author":  "@{user=; role=AUTHOR; approved=False; status=UNAPPROVED}",
                   "reviewers":  "             ",
                   "participants":  "",
                   "properties":  "@{mergeResult=; resolvedTaskCount=0; openTaskCount=0}",
                   "links":  "@{self=System.Object[]}"
               }
           ],
"start":  0
}

Expected Output something similiar to the below.

$id =1862
$fromRefbranch.displayid = schema/2018.7.63125
1

1 Answer 1

1

There are probably better solutions...

$jsonfile = Get-Content C:\json.txt -Raw | ConvertFrom-Json
$values = $jsonfile.values | Select-Object -Property id,@{Label='displayId';Expression={($_.fromRef.Split(';') | Select-String displayId).Line.Split('=')[1]}}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.