Skip to content

Commit 97879fd

Browse files
jknaudt21kzu
authored andcommitted
Add peeking for json array files
1 parent b7eab04 commit 97879fd

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/JsonPeek/JsonPeek.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public override bool Execute()
6060
if (string.IsNullOrEmpty(content))
6161
return Log.Warn("JPE04", $"Empty JSON content.", true);
6262

63-
var json = JObject.Parse(content!);
63+
var json = JToken.Parse(content!);
6464

6565
Result = json.SelectTokens(Query)
6666
// NOTE: we cannot create items with empty ItemSpec, so skip them entirely.

src/Tests/Peek.targets

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,37 @@
162162
<Error Condition="'$(Port)' != '80'" Text="Expected '80' but was $(Port)" />
163163
<Error Condition="'$(Ssl)' != 'true'" Text="Expected 'true' but was $(Ssl)" />
164164
</Target>
165+
166+
<Target Name="PeekArray">
167+
<PropertyGroup>
168+
<Json>
169+
[
170+
{
171+
"contributor": "jd",
172+
"favnumber": 10,
173+
"iscool": true
174+
},
175+
{
176+
"name": "impostor",
177+
"favnumber": 11,
178+
"iscool": false
179+
}
180+
]
181+
</Json>
182+
</PropertyGroup>
183+
184+
<JsonPeek Content="$(Json)" Query="$[0]">
185+
<Output TaskParameter="Result" ItemName="Array" />
186+
</JsonPeek>
187+
<PropertyGroup>
188+
<Contributor>@(Array -> '%(contributor)')</Contributor>
189+
<FavNumber>@(Array -> '%(favnumber)')</FavNumber>
190+
<IsCool>@(Array -> '%(iscool)')</IsCool>
191+
</PropertyGroup>
192+
193+
<Error Condition="'$(Contributor)' != 'jd'" Text="Expected 'jd' but was $(Contributor)" />
194+
<Error Condition="'$(FavNumber)' != '10'" Text="Expected '10' but was $(FavNumber)" />
195+
<Error Condition="'$(IsCool)' != 'true'" Text="Expected 'true' but was $(IsCool)" />
196+
</Target>
165197

166198
</Project>

0 commit comments

Comments
 (0)