Skip to content

Improve Function for a True Json-LD API and Debugging.#26

Open
AniTexs wants to merge 5 commits intoPoshWeb:mainfrom
AniTexs:main
Open

Improve Function for a True Json-LD API and Debugging.#26
AniTexs wants to merge 5 commits intoPoshWeb:mainfrom
AniTexs:main

Conversation

@AniTexs
Copy link
Copy Markdown

@AniTexs AniTexs commented Apr 13, 2026

  • Enhanced Get-JsonLD web request options
    • Added -SkipCertificateCheck passthrough to Invoke-RestMethod
    • Added -Authentication passthrough to Invoke-RestMethod
    • Added -UserAgent passthrough to Invoke-RestMethod
    • Added -Headers passthrough to Invoke-RestMethod
  • Added -IgnoreCache switch to bypass cached responses and force a fresh request
  • Added Write-Verbose, Write-Debug, and Write-Warning output throughout for improved diagnostics
  • Added error handling with try/catch around web requests and JSON parsing
  • Fixed output formatting for direct JSON-LD API responses (true application/ld+json endpoints)
    • @graph document responses now emit individual graph entities rather than the wrapper object
    • Direct JSON-LD object and JSON-text responses are detected and processed without requiring HTML script-tag extraction

Reason for this was because of the https://unlocode.unece.org/docs/web-vocabulary API

  * Added `-SkipCertificateCheck` passthrough to `Invoke-RestMethod`
  * Added `-Authentication` passthrough to `Invoke-RestMethod`
  * Added `-UserAgent` passthrough to `Invoke-RestMethod`
  * Added `-Headers` passthrough to `Invoke-RestMethod`
* Added `-IgnoreCache` switch to bypass cached responses and force a fresh request
* Added `Write-Verbose`, `Write-Debug`, and `Write-Warning` output throughout for improved diagnostics
* Added error handling with `try/catch` around web requests and JSON parsing
* Fixed output formatting for direct JSON-LD API responses (true `application/ld+json` endpoints)
  * `@graph` document responses now emit individual graph entities rather than the wrapper object
  * Direct JSON-LD object and JSON-text responses are detected and processed without requiring HTML script-tag extraction
Copilot AI review requested due to automatic review settings April 13, 2026 13:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Get-JsonLD to better support “true” JSON-LD API endpoints (e.g., application/ld+json responses), adds passthrough options for Invoke-RestMethod, and improves diagnostics and error handling.

Changes:

  • Added new web-request passthrough parameters (-SkipCertificateCheck, -Authentication, -UserAgent, -Headers) and -IgnoreCache.
  • Added verbose/debug/warning logging plus try/catch around web requests and JSON parsing.
  • Improved handling of direct JSON-LD API responses (including emitting @graph entries rather than the wrapper document).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
Commands/Get-JsonLD.ps1 Adds request passthroughs, caching controls, more diagnostics, improved error handling, and direct JSON-LD response support/formatting.
CHANGELOG.md Documents the new parameters, caching behavior, diagnostics, and direct JSON-LD handling changes.
Comments suppressed due to low confidence (1)

Commands/Get-JsonLD.ps1:118

  • In the output filter, $context is only set when @context is a string, but it’s never cleared per object. When processing multiple JSON-LD objects, an object without @context can inherit the previous object’s $context, producing incorrect pstypename values. Reset $context (e.g., $context = $null) at the start of the filter or compute typeName without relying on a cross-object variable.
            $in = $_
            $shouldOutput = $true
            if ($in.'@context' -is [string]) {
                $context  = $in.'@context'
            }
            if ($in.'@graph') {
                if ($in.pstypenames -ne 'application/ld+json') {
                    $in.pstypenames.insert(0,'application/ld+json')
                }
                foreach ($graphObject in $in.'@graph') {
                    $graphObject | output
                }
                # Emit graph entries instead of the wrapper document.
                $shouldOutput = $false
            }
            elseif ($in.'@type') {

                $typeName = if ($context) {
                    $context, $in.'@type' -join '/'
                } else {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +164 to +166
($propertyNames -contains '@context') -or
($propertyNames -contains '@type') -or
($propertyNames -contains '@graph')
Comment on lines +252 to +256
$jsonLdObjects = if ($restResponse -is [System.Collections.IEnumerable] -and -not ($restResponse -is [string])) {
@($restResponse)
} else {
@($restResponse)
}

---

## JSON-LD 0.1.1.1 - Pull Request
@AniTexs AniTexs marked this pull request as draft April 13, 2026 13:32
AniTexs and others added 2 commits April 13, 2026 15:41
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the Get-JsonLD PowerShell cmdlet to better support “true” JSON-LD API endpoints (e.g., application/ld+json responses), adds additional Invoke-RestMethod passthrough options, and improves diagnostics with verbose/debug/warning output and additional try/catch handling.

Changes:

  • Added Invoke-RestMethod passthrough parameters (-SkipCertificateCheck, -Authentication, -UserAgent, -Headers) and cache-bypass behavior (-IgnoreCache).
  • Improved handling of direct JSON-LD API responses (object and JSON text), including emitting @graph entries instead of wrapper documents.
  • Added more diagnostic output and additional error handling around web requests and JSON parsing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
Commands/Get-JsonLD.ps1 Adds web request options, cache controls, diagnostics, and direct JSON-LD response handling logic.
CHANGELOG.md Documents the above behavior changes in a new changelog entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* Remove Parameter `-RawHtml` since it was never used
* Added ValidateSet to the `-Authentication` parameter
* More error handling and stability.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@AniTexs AniTexs marked this pull request as ready for review April 13, 2026 14:36
@AniTexs
Copy link
Copy Markdown
Author

AniTexs commented Apr 13, 2026

@StartAutomating would you be so kind to review this PR and make a new version?

@StartAutomating
Copy link
Copy Markdown
Member

@AniTexs Taking a look. It appears copilot did a lot more than initially requested, and these changes would break other functionality (like, for example, converting a graph to a json schema or lexicon).

I'm ok with part of this, but not ok with how copilot has approached other parts of it.

It appears that the .jsonld direct file is a "good catch". The Uri alias is also fine.

I'm less inclined to support all of the parameters from Invoke-RestMethod/Invoke-WebRequest, as this sort of data should not be behind authentication (and, taken to it's logical conclusion, this would vastly expand the parameter count on a purposefully simple function)

Will make the changes for #12, and opened #27 to track this concern.

@AniTexs
Copy link
Copy Markdown
Author

AniTexs commented Apr 13, 2026

Yea, copilot did go a bit overboard but it also catched some stuff I forgot (:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants