@@ -122,7 +122,12 @@ public virtual JToken Compact(Context activeCtx, string activeProperty, JToken e
122
122
JObject result = new JObject ( ) ;
123
123
// 7)
124
124
JArray keys = new JArray ( element . GetKeys ( ) ) ;
125
- keys . SortInPlace ( ) ;
125
+
126
+ if ( ! opts . GetPreserveOrder ( ) )
127
+ {
128
+ keys . SortInPlace ( ) ;
129
+ }
130
+
126
131
foreach ( string expandedProperty in keys )
127
132
{
128
133
JToken expandedValue = elem [ expandedProperty ] ;
@@ -491,7 +496,12 @@ public virtual JToken Expand(Context activeCtx, string activeProperty, JToken el
491
496
JObject result = new JObject ( ) ;
492
497
// 7)
493
498
JArray keys = new JArray ( element . GetKeys ( ) ) ;
494
- keys . SortInPlace ( ) ;
499
+
500
+ if ( ! opts . GetPreserveOrder ( ) )
501
+ {
502
+ keys . SortInPlace ( ) ;
503
+ }
504
+
495
505
foreach ( string key in keys )
496
506
{
497
507
JToken value = elem [ key ] ;
@@ -808,7 +818,12 @@ public virtual JToken Expand(Context activeCtx, string activeProperty, JToken el
808
818
expandedValue = new JArray ( ) ;
809
819
// 7.6.2)
810
820
JArray indexKeys = new JArray ( value . GetKeys ( ) ) ;
811
- indexKeys . SortInPlace ( ) ;
821
+
822
+ if ( ! opts . GetPreserveOrder ( ) )
823
+ {
824
+ indexKeys . SortInPlace ( ) ;
825
+ }
826
+
812
827
foreach ( string index in indexKeys )
813
828
{
814
829
JToken indexValue = ( ( JObject ) value ) [ index ] ;
@@ -1290,7 +1305,12 @@ private void GenerateNodeMap(JToken element, JObject nodeMap,
1290
1305
}
1291
1306
// 6.11)
1292
1307
JArray keys = new JArray ( element . GetKeys ( ) ) ;
1293
- keys . SortInPlace ( ) ;
1308
+
1309
+ if ( ! opts . GetPreserveOrder ( ) )
1310
+ {
1311
+ keys . SortInPlace ( ) ;
1312
+ }
1313
+
1294
1314
foreach ( string property_1 in keys )
1295
1315
{
1296
1316
var eachProperty_1 = property_1 ;
@@ -1405,7 +1425,7 @@ public virtual JArray Frame(JToken input, JArray frame)
1405
1425
{
1406
1426
state . omitDefault = this . opts . GetOmitDefault ( ) . Value ;
1407
1427
}
1408
- // use tree map so keys are sotred by default
1428
+ // use tree map so keys are sorted by default
1409
1429
// XXX BUG BUG BUG XXX (sblom) Figure out where this needs to be sorted and use extension methods to return sorted enumerators or something!
1410
1430
JObject nodes = new JObject ( ) ;
1411
1431
GenerateNodeMap ( input , nodes ) ;
@@ -1436,7 +1456,12 @@ private void Frame(JsonLdApi.FramingContext state, JObject nodes
1436
1456
bool explicitOn = GetFrameFlag ( frame , "@explicit" , state . @explicit ) ;
1437
1457
// add matches to output
1438
1458
JArray ids = new JArray ( matches . GetKeys ( ) ) ;
1439
- ids . SortInPlace ( ) ;
1459
+
1460
+ if ( ! opts . GetPreserveOrder ( ) )
1461
+ {
1462
+ ids . SortInPlace ( ) ;
1463
+ }
1464
+
1440
1465
foreach ( string id in ids )
1441
1466
{
1442
1467
if ( property == null )
@@ -1499,7 +1524,12 @@ private void Frame(JsonLdApi.FramingContext state, JObject nodes
1499
1524
// iterate over subject properties
1500
1525
JObject element = ( JObject ) matches [ id ] ;
1501
1526
JArray props = new JArray ( element . GetKeys ( ) ) ;
1502
- props . SortInPlace ( ) ;
1527
+
1528
+ if ( ! opts . GetPreserveOrder ( ) )
1529
+ {
1530
+ props . SortInPlace ( ) ;
1531
+ }
1532
+
1503
1533
foreach ( string prop in props )
1504
1534
{
1505
1535
// copy keywords to output
@@ -1576,7 +1606,12 @@ private void Frame(JsonLdApi.FramingContext state, JObject nodes
1576
1606
}
1577
1607
// handle defaults
1578
1608
props = new JArray ( frame . GetKeys ( ) ) ;
1579
- props . SortInPlace ( ) ;
1609
+
1610
+ if ( ! opts . GetPreserveOrder ( ) )
1611
+ {
1612
+ props . SortInPlace ( ) ;
1613
+ }
1614
+
1580
1615
foreach ( string prop_1 in props )
1581
1616
{
1582
1617
// skip keywords
@@ -2116,7 +2151,12 @@ public virtual JArray FromRDF(RDFDataset dataset)
2116
2151
JArray result = new JArray ( ) ;
2117
2152
// 6)
2118
2153
JArray ids = new JArray ( defaultGraph . GetKeys ( ) ) ;
2119
- ids . SortInPlace ( ) ;
2154
+
2155
+ if ( ! opts . GetPreserveOrder ( ) )
2156
+ {
2157
+ ids . SortInPlace ( ) ;
2158
+ }
2159
+
2120
2160
foreach ( string subject_1 in ids )
2121
2161
{
2122
2162
JsonLdApi . NodeMapNode node = ( NodeMapNode ) defaultGraph [ subject_1 ] ;
@@ -2127,7 +2167,12 @@ public virtual JArray FromRDF(RDFDataset dataset)
2127
2167
node [ "@graph" ] = new JArray ( ) ;
2128
2168
// 6.1.2)
2129
2169
JArray keys = new JArray ( graphMap [ subject_1 ] . GetKeys ( ) ) ;
2130
- keys . SortInPlace ( ) ;
2170
+
2171
+ if ( ! opts . GetPreserveOrder ( ) )
2172
+ {
2173
+ keys . SortInPlace ( ) ;
2174
+ }
2175
+
2131
2176
foreach ( string s in keys )
2132
2177
{
2133
2178
JsonLdApi . NodeMapNode n = ( NodeMapNode ) graphMap [ subject_1 ] [ s ] ;
0 commit comments