Reputation: 35
I have written a PowerShell script which loads a json file and performs certain function on it. I am using:
$json = Get-Content 'C:\Users\Documents\test.json' | Out-String | ConvertFrom-Json
to load the file which works. But I want to store both these files in a git hub repository. How can I access the json file path once I store both the files in the same directory in a GitHub repository?
I am new to using GitHub so any help would be appreciated.
Upvotes: 1
Views: 4967
Reputation: 35
I ended up using path binding to reference the file
$path = join-path $psscriptroot "env.json"
This sources to the directory where all the files are loaded.
Upvotes: 0
Reputation: 58951
If you want to work with a remote path, you can use the webclient to download the file as a string and convert it using the ConvertFrom-Json
cmdlet:
$jsonPath = 'https://raw.githubusercontent.com/jaypat/documents/master/test.json'
$json = (New-Object System.Net.WebClient).DownloadString($jsonPath) | ConvertFrom-Json
Upvotes: 2
Reputation: 5091
You might need to either use the Github API or commit and push using git. For the latter you should do something like the following from the local git repository:
git add test.json
git commit -m "Message for what changes you've made"
git pull
git push origin master
It'd be really helpful if you first read and understood what git is and how it works. Then you'd be ablt to use github seamlessly. Here is a great interactive tutorial for it: https://try.github.io/levels/1/challenges/1
Upvotes: 0