@@ -122,7 +122,12 @@ public virtual JToken Compact(Context activeCtx, string activeProperty, JToken e
122122 JObject result = new JObject ( ) ;
123123 // 7)
124124 JArray keys = new JArray ( element . GetKeys ( ) ) ;
125- keys . SortInPlace ( ) ;
125+
126+ if ( ! opts . GetPreserveOrder ( ) )
127+ {
128+ keys . SortInPlace ( ) ;
129+ }
130+
126131 foreach ( string expandedProperty in keys )
127132 {
128133 JToken expandedValue = elem [ expandedProperty ] ;
@@ -491,7 +496,12 @@ public virtual JToken Expand(Context activeCtx, string activeProperty, JToken el
491496 JObject result = new JObject ( ) ;
492497 // 7)
493498 JArray keys = new JArray ( element . GetKeys ( ) ) ;
494- keys . SortInPlace ( ) ;
499+
500+ if ( ! opts . GetPreserveOrder ( ) )
501+ {
502+ keys . SortInPlace ( ) ;
503+ }
504+
495505 foreach ( string key in keys )
496506 {
497507 JToken value = elem [ key ] ;
@@ -808,7 +818,12 @@ public virtual JToken Expand(Context activeCtx, string activeProperty, JToken el
808818 expandedValue = new JArray ( ) ;
809819 // 7.6.2)
810820 JArray indexKeys = new JArray ( value . GetKeys ( ) ) ;
811- indexKeys . SortInPlace ( ) ;
821+
822+ if ( ! opts . GetPreserveOrder ( ) )
823+ {
824+ indexKeys . SortInPlace ( ) ;
825+ }
826+
812827 foreach ( string index in indexKeys )
813828 {
814829 JToken indexValue = ( ( JObject ) value ) [ index ] ;
@@ -1290,7 +1305,12 @@ private void GenerateNodeMap(JToken element, JObject nodeMap,
12901305 }
12911306 // 6.11)
12921307 JArray keys = new JArray ( element . GetKeys ( ) ) ;
1293- keys . SortInPlace ( ) ;
1308+
1309+ if ( ! opts . GetPreserveOrder ( ) )
1310+ {
1311+ keys . SortInPlace ( ) ;
1312+ }
1313+
12941314 foreach ( string property_1 in keys )
12951315 {
12961316 var eachProperty_1 = property_1 ;
@@ -1405,7 +1425,7 @@ public virtual JArray Frame(JToken input, JArray frame)
14051425 {
14061426 state . omitDefault = this . opts . GetOmitDefault ( ) . Value ;
14071427 }
1408- // use tree map so keys are sotred by default
1428+ // use tree map so keys are sorted by default
14091429 // XXX BUG BUG BUG XXX (sblom) Figure out where this needs to be sorted and use extension methods to return sorted enumerators or something!
14101430 JObject nodes = new JObject ( ) ;
14111431 GenerateNodeMap ( input , nodes ) ;
@@ -1436,7 +1456,12 @@ private void Frame(JsonLdApi.FramingContext state, JObject nodes
14361456 bool explicitOn = GetFrameFlag ( frame , "@explicit" , state . @explicit ) ;
14371457 // add matches to output
14381458 JArray ids = new JArray ( matches . GetKeys ( ) ) ;
1439- ids . SortInPlace ( ) ;
1459+
1460+ if ( ! opts . GetPreserveOrder ( ) )
1461+ {
1462+ ids . SortInPlace ( ) ;
1463+ }
1464+
14401465 foreach ( string id in ids )
14411466 {
14421467 if ( property == null )
@@ -1499,7 +1524,12 @@ private void Frame(JsonLdApi.FramingContext state, JObject nodes
14991524 // iterate over subject properties
15001525 JObject element = ( JObject ) matches [ id ] ;
15011526 JArray props = new JArray ( element . GetKeys ( ) ) ;
1502- props . SortInPlace ( ) ;
1527+
1528+ if ( ! opts . GetPreserveOrder ( ) )
1529+ {
1530+ props . SortInPlace ( ) ;
1531+ }
1532+
15031533 foreach ( string prop in props )
15041534 {
15051535 // copy keywords to output
@@ -1576,7 +1606,12 @@ private void Frame(JsonLdApi.FramingContext state, JObject nodes
15761606 }
15771607 // handle defaults
15781608 props = new JArray ( frame . GetKeys ( ) ) ;
1579- props . SortInPlace ( ) ;
1609+
1610+ if ( ! opts . GetPreserveOrder ( ) )
1611+ {
1612+ props . SortInPlace ( ) ;
1613+ }
1614+
15801615 foreach ( string prop_1 in props )
15811616 {
15821617 // skip keywords
@@ -2116,7 +2151,12 @@ public virtual JArray FromRDF(RDFDataset dataset)
21162151 JArray result = new JArray ( ) ;
21172152 // 6)
21182153 JArray ids = new JArray ( defaultGraph . GetKeys ( ) ) ;
2119- ids . SortInPlace ( ) ;
2154+
2155+ if ( ! opts . GetPreserveOrder ( ) )
2156+ {
2157+ ids . SortInPlace ( ) ;
2158+ }
2159+
21202160 foreach ( string subject_1 in ids )
21212161 {
21222162 JsonLdApi . NodeMapNode node = ( NodeMapNode ) defaultGraph [ subject_1 ] ;
@@ -2127,7 +2167,12 @@ public virtual JArray FromRDF(RDFDataset dataset)
21272167 node [ "@graph" ] = new JArray ( ) ;
21282168 // 6.1.2)
21292169 JArray keys = new JArray ( graphMap [ subject_1 ] . GetKeys ( ) ) ;
2130- keys . SortInPlace ( ) ;
2170+
2171+ if ( ! opts . GetPreserveOrder ( ) )
2172+ {
2173+ keys . SortInPlace ( ) ;
2174+ }
2175+
21312176 foreach ( string s in keys )
21322177 {
21332178 JsonLdApi . NodeMapNode n = ( NodeMapNode ) graphMap [ subject_1 ] [ s ] ;
0 commit comments