@@ -350,6 +350,12 @@ func (j *JSONQ) prepare() *JSONQ {
350
350
if len (j .queries ) > 0 {
351
351
j .processQuery ()
352
352
}
353
+ if j .distinctProperty != "" {
354
+ j .distinct ()
355
+ }
356
+ if len (j .attributes ) > 0 {
357
+ j .jsonContent = j .only (j .attributes ... )
358
+ }
353
359
j .queryIndex = 0
354
360
return j
355
361
}
@@ -545,27 +551,18 @@ func (j *JSONQ) Reset() *JSONQ {
545
551
// Get return the result
546
552
func (j * JSONQ ) Get () interface {} {
547
553
j .prepare ()
548
- if j .distinctProperty != "" {
549
- j .distinct ()
550
- }
551
554
if j .offsetRecords != 0 {
552
555
j .offset ()
553
556
}
554
557
if j .limitRecords != 0 {
555
558
j .limit ()
556
559
}
557
- if len (j .attributes ) > 0 {
558
- return j .only (j .attributes ... )
559
- }
560
560
return j .jsonContent
561
561
}
562
562
563
563
// First returns the first element of a list
564
564
func (j * JSONQ ) First () interface {} {
565
565
j .prepare ()
566
- if j .distinctProperty != "" {
567
- j .distinct ()
568
- }
569
566
if arr , ok := j .jsonContent .([]interface {}); ok {
570
567
if len (arr ) > 0 {
571
568
return arr [0 ]
@@ -577,9 +574,6 @@ func (j *JSONQ) First() interface{} {
577
574
// Last returns the last element of a list
578
575
func (j * JSONQ ) Last () interface {} {
579
576
j .prepare ()
580
- if j .distinctProperty != "" {
581
- j .distinct ()
582
- }
583
577
if arr , ok := j .jsonContent .([]interface {}); ok {
584
578
if l := len (arr ); l > 0 {
585
579
return arr [l - 1 ]
@@ -596,9 +590,6 @@ func (j *JSONQ) Nth(index int) interface{} {
596
590
}
597
591
598
592
j .prepare ()
599
- if j .distinctProperty != "" {
600
- j .distinct ()
601
- }
602
593
if arr , ok := j .jsonContent .([]interface {}); ok {
603
594
alen := len (arr )
604
595
if alen == 0 {
@@ -626,9 +617,6 @@ func (j *JSONQ) Find(path string) interface{} {
626
617
// This could be a length of list/array/map
627
618
func (j * JSONQ ) Count () int {
628
619
j .prepare ()
629
- if j .distinctProperty != "" {
630
- j .distinct ()
631
- }
632
620
lnth := 0
633
621
// list of items
634
622
if list , ok := j .jsonContent .([]interface {}); ok {
0 commit comments