Skip to content

ConvertFrom-Json does not convert Newtonsoft.Json specific metadata properties in root object #7307

Closed

Description

Steps to reproduce

> '{"$id": 1, "$type": "System.String", "id": "value"}' | ConvertFrom-Json
  1. Add $id and $type properties to a json object
  2. Pipe object to ConvertFrom-Json Cmdlet
  3. Notice that $id and $type properties are missing from resulting PSCustomObject

Expected behavior

ConvertFrom-Json does not ignore properties when deserializing into generic PSCustomObject, regardless of their name.

> '{"$id": 1, "$type": "System.String", "id": "value"}' | ConvertFrom-Json

$id $type         id
--- -----         --
  1 System.String value

Actual behavior

> '{"$id": 1, "$type": "System.String", "id": "value"}' | ConvertFrom-Json

id
--
value

Additional Notes

  • Issue does not occur when metadata properties are deeper in the hierarchy.
  • Other Newtonsoft.Json metadata properties include $values and $ref.

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.3
PSEdition                      Core
GitCommitId                    v6.1.0-preview.3
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. changed the title [-]ConvertFrom-Json silently ignores Newtonsoft.Json specific metadata properties in root object[/-] [+]ConvertFrom-Json does not convert Newtonsoft.Json specific metadata properties in root object[/+] on Jul 18, 2018
  2. markekraus commented on Jul 18, 2018

    @markekraus
    Contributor

    I can repro this. It also repros with -AsHashtable and it does not repro on nested objects, only root.

    ('{"a":{"$id": 1, "$type": "System.String", "id": "value"}}' | ConvertFrom-Json).a

    result:

    $id $type         id
    --- -----         --
      1 System.String value
    
  3. added
    Issue-Bug
    on Jul 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugResolution-FixedWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions