Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions kotlin-jsonq.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":kotlin-jsonq" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":kotlin-jsonq" />
</configuration>
</facet>
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="true" />
</configuration>
</facet>
<facet type="kotlin-language" name="Kotlin">
<configuration version="3" platform="JVM 1.8" useProjectSettings="false">
<compilerSettings />
<compilerArguments>
<option name="destination" value="$MODULE_DIR$/build/classes/kotlin/main" />
<option name="noStdlib" value="true" />
<option name="noReflect" value="true" />
<option name="moduleName" value="kotlin-jsonq" />
<option name="jvmTarget" value="1.8" />
<option name="addCompilerBuiltIns" value="true" />
<option name="loadBuiltInsFromDependencies" value="true" />
<option name="languageVersion" value="1.1" />
<option name="apiVersion" value="1.1" />
<option name="pluginOptions">
<array />
</option>
<option name="pluginClasspaths">
<array />
</option>
</compilerArguments>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/build/classes/java/main" />
<output-test url="file://$MODULE_DIR$/build/classes/java/test" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/kotlin" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" scope="PROVIDED" name="kotlin-stdlib-jre8-1.1.4-3" level="project" />
<orderEntry type="library" exported="" scope="PROVIDED" name="minimal-json-0.9.5" level="project" />
<orderEntry type="library" exported="" scope="PROVIDED" name="kotlin-stdlib-jre7-1.1.4-3" level="project" />
<orderEntry type="library" exported="" scope="PROVIDED" name="kotlin-stdlib-1.1.4-3" level="project" />
<orderEntry type="library" exported="" scope="PROVIDED" name="annotations-13.0" level="project" />
<orderEntry type="library" exported="" scope="RUNTIME" name="kotlin-stdlib-jre8-1.1.4-3" level="project" />
<orderEntry type="library" exported="" scope="RUNTIME" name="minimal-json-0.9.5" level="project" />
<orderEntry type="library" exported="" scope="RUNTIME" name="kotlin-stdlib-jre7-1.1.4-3" level="project" />
<orderEntry type="library" exported="" scope="RUNTIME" name="kotlin-stdlib-1.1.4-3" level="project" />
<orderEntry type="library" exported="" scope="RUNTIME" name="annotations-13.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="kotlin-stdlib-jre8-1.1.4-3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="minimal-json-0.9.5" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="kotlin-stdlib-jre7-1.1.4-3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="kotlin-stdlib-1.1.4-3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="annotations-13.0" level="project" />
</component>
</module>
22 changes: 22 additions & 0 deletions src/main/kotlin/ninja/sakib/jsonq/ext/JsonArrayExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ninja.sakib.jsonq.ext

import com.eclipsesource.json.Json
import com.eclipsesource.json.JsonArray
import com.eclipsesource.json.JsonObject
import com.eclipsesource.json.JsonValue
import ninja.sakib.jsonq.utils.*

Expand Down Expand Up @@ -169,3 +170,24 @@ fun JsonArray.max(key: String): JsonValue {
fun JsonArray.avg(key: String): Double {
return this.sum(key) / this.size()
}

fun JsonArray.count(): Int {
return size()
}

fun JsonArray.select(vararg key: String): JsonArray {
val res = JsonArray()
for (j in this) {
val jObject = j as JsonObject
val json = JsonObject()
for (k in key) {
val v = jObject.get(k)
if (v != null) {
json.add(k, v)
}
}
res.add(json)
}
return res
}