Skip to content

Commit 424d917

Browse files
committed
ConvertFrom-Json/Different-number-types
1 parent 796cbbb commit 424d917

File tree

7 files changed

+58
-37
lines changed

7 files changed

+58
-37
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
task Test-1.ps1 {
3+
$1, $2, $3, $4 = ./Test-1.ps1
4+
5+
if ($PSEdition -eq 'Core') {
6+
equals $1 Int64
7+
equals $2 Int64
8+
equals $3 Double
9+
}
10+
else {
11+
equals $1 Int32
12+
equals $2 Int32
13+
equals $3 Decimal
14+
}
15+
16+
equals $4 Int64
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# `ConvertTo-Json` different number types
2+
3+
## Integer numbers
4+
5+
- PowerShell Desktop imports integers as `Int32` or `Int64`.
6+
- PowerShell Core imports integers as `Int64`.
7+
8+
## Floating point numbers
9+
10+
- PowerShell Desktop imports floating point numbers as `Decimal`.
11+
- PowerShell Core imports floating point numbers as `Doubles`.
12+
13+
The script [Test-1.ps1](Test-1.ps1) shows results for various numbers.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
# some numeric data
3+
$data = [pscustomobject]@{
4+
Int32 = 42
5+
Int64 = 42L
6+
Double = 3.14
7+
BigInt = 9123123123
8+
}
9+
10+
# round trip
11+
$json = $data | ConvertTo-Json
12+
$data = $json | ConvertFrom-Json
13+
14+
# 5.1: Int32
15+
# 7.4: Int64
16+
$data.Int32.GetType().Name
17+
18+
# 5.1: Int32
19+
# 7.4: Int64
20+
$data.Int64.GetType().Name
21+
22+
# 5.1: Decimal
23+
# 7.4: Double
24+
$data.Double.GetType().Name
25+
26+
# Int64
27+
$data.BigInt.GetType().Name

Cmdlets/ConvertFrom-Json/v6-long-integers/.test.ps1

-13
This file was deleted.

Cmdlets/ConvertFrom-Json/v6-long-integers/README.md

-11
This file was deleted.

Cmdlets/ConvertFrom-Json/v6-long-integers/Test-1.long.integer.ps1

-12
This file was deleted.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ to their directory. See also [TESTS]. Some scripts require
115115
- ConvertFrom-Csv
116116
- [`ConvertFrom-Csv` has undocumented partial comment support](Cmdlets/ConvertFrom-Csv/Partial-comment-support)
117117
- ConvertFrom-Json
118+
- [`ConvertTo-Json` different number types](Cmdlets/ConvertFrom-Json/Different-number-types)
118119
- [`ConvertFrom-Json` returns an array not unrolled](Cmdlets/ConvertFrom-Json/Not-unrolled-result)
119120
- [`ConvertFrom-Json` pipeline input](Cmdlets/ConvertFrom-Json/Piping-content)
120-
- [`ConvertFrom-Json` long integers in v6](Cmdlets/ConvertFrom-Json/v6-long-integers)
121121
- ConvertTo-Json
122122
- [`ConvertTo-Json` Array as PSObject](Cmdlets/ConvertTo-Json/Array-as-PSObject)
123123
- [`ConvertTo-Json` without `Compress` may change data](Cmdlets/ConvertTo-Json/v3-Without-Compress)

0 commit comments

Comments
 (0)