the items are only required for the order_type: ORDER, but I can't make a conditional that only requires this property for that specific case, that is, if any order_type different from ORDER comes without items it can be validated correctly, but if an ORDER comes without them I mark it incorrectly.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://json-schema.org/draft-07/schema#",
"title": "Validaciones sobre el esquema Order",
"type": "object",
"properties": {
"warehouse_id": {
"type": [
"string"
]
},
"operation_type": {
"type": [
"string"
]
},
"order_id": {
"type": [
"number"
]
},
"items": {
"type": [
"array"
],
"minItems": 1,
"items": {
"type": [
"object"
],
"properties": {
"sku": {
"type": [
"string"
],
"minLength": 1,
"maxLength": 50
},
"quantity": {
"type": [
"integer"
],
"minimum": 1
}
},
"required": [
"sku",
"quantity"
],
"additionalProperties": false
}
},
"attributes": {
"type": [
"object"
],
"properties": {
"order_type": {
"type": [
"string"
],
"enum": [
"ORDER",
"TRANSFER",
"WITHDRAWAL",
"DISPOSAL",
"FRESH"
]
},
"etd": {
"type": [
"string"
],
"pattern": "^(\\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(?:T)(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]):(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])(?:Z)$"
},
"volume": {
"type": [
"integer", "null"
],
"minimum": 0
},
"typology": true
},
"required": [
"order_type"
],
"allOf": [
{
"if": {
"properties": {
"order_type": {
"const": "ORDER"
}
},
"required": [
"order_type",
"items"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true,
"typology": {
"type": [
"string", "null"
],
"enum": [
"CONVEYABLE",
"NON_CONVEYABLE"
]
}
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"order_type": {
"const": "TRANSFER"
}
},
"required": [
"order_type"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"order_type": {
"const": "WITHDRAWAL"
}
},
"required": [
"order_type"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"order_type": {
"const": "DISPOSAL"
}
},
"required": [
"order_type"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
}
]
}
},
"required": [
"warehouse_id",
"operation_type",
"attributes"
],
"additionalProperties": false
}
try to make a conditional with an if at the end of the properties like this
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://json-schema.org/draft-07/schema#",
"title": "Validaciones sobre el esquema Order",
"type": "object",
"properties": {
"warehouse_id": {
"type": [
"string"
]
},
"operation_type": {
"type": [
"string"
]
},
"order_id": {
"type": [
"number"
]
},
"items": {
"type": [
"array"
],
"minItems": 1,
"items": {
"type": [
"object"
],
"properties": {
"sku": {
"type": [
"string"
],
"minLength": 1,
"maxLength": 50
},
"quantity": {
"type": [
"integer"
],
"minimum": 1
}
},
"required": [
"sku",
"quantity"
],
"additionalProperties": false
}
},
"attributes": {
"type": [
"object"
],
"properties": {
"order_type": {
"type": [
"string"
],
"enum": [
"ORDER",
"TRANSFER",
"WITHDRAWAL",
"DISPOSAL",
"FRESH"
]
},
"etd": {
"type": [
"string"
],
"pattern": "^(\\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(?:T)(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]):(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])(?:Z)$"
},
"volume": {
"type": [
"integer", "null"
],
"minimum": 0
},
"typology": true
},
"required": [
"order_type"
],
"allOf": [
{
"if": {
"properties": {
"order_type": {
"const": "ORDER"
}
},
"required": [
"order_type",
"items"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true,
"typology": {
"type": [
"string", "null"
],
"enum": [
"CONVEYABLE",
"NON_CONVEYABLE"
]
}
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"order_type": {
"const": "TRANSFER"
}
},
"required": [
"order_type"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"order_type": {
"const": "WITHDRAWAL"
}
},
"required": [
"order_type"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"order_type": {
"const": "DISPOSAL"
}
},
"required": [
"order_type"
]
},
"then": {
"properties": {
"order_type": true,
"etd": true,
"volume": true
},
"required": [
"order_type",
"etd"
],
"additionalProperties": false
}
}
]
}
},
"allOf": [
{
"if": {
"properties": {
"order_type": {
"const": "ORDER"
}
},
"required": [
"order_type"
]
},
"then": {
"properties": {
"items": true,
"order_type": true,
"etd": true,
"volume": true
},
"required": [
"order_type",
"etd",
"items"
],
"additionalProperties": false
}
}
],
"required": [
"warehouse_id",
"operation_type",
"attributes"
],
"additionalProperties": false
}
this request should be marked as incorrect, cause dont have any items, that are required:
{
"warehouse_id": "ARTW01",
"operation_type": "outbound",
"order_id": 41789301078,
"attributes": {
"volume": 1350,
"etd": "2022-11-11T18:25:00Z",
"order_type": "ORDER"
}
}
Here's the assertion you described with all the unrelated parts removed. The trick is that the if need to describe the nested path to the value being checked.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"attributes": {
"type": "object",
"properties": {
"order_type": { "enum": ["ORDER", "TRANSFER", "WITHDRAWAL", "DISPOSAL", "FRESH"] }
},
"required": ["order_type"]
},
"items": { "type": "array" }
},
"allOf": [
{
"if": {
"type": "object",
"properties": {
"attributes": {
"type": "object",
"properties": {
"order_type": { "const": "ORDER" }
},
"required": ["order_type"]
}
},
"required": ["attributes"]
},
"then": { "required": ["items"] }
}
]
}
I want to get the max and min value of the emp salary based on currency. every employee has a salary range based on currency also all the details in response should be unique. while I am using aggregation function min and max but it fetches the max and min value of salary amount but I need to get max and min based on currency field.
Sample Data:
[
{
"id": "1",
"emp_name": "emp1",
"data": [
{
"emp_country": "country1",
"emp_city": "city1",
"salary": [
{
"currency": "INR",
"amount": 5000
},
{
"currency": "INR",
"amount": 600
},
{
"currency": "MXN",
"amount": 400
}
]
},
{
"emp_country": "country1",
"emp_city": "city2",
"salary": [
{
"currency": "DOLLER",
"amount": 5000
},
{
"currency": "DOLLER",
"amount": 200
},
{
"currency": "MXN",
"amount": 400
}
]
}
]
},
{
"id": "2",
"emp_name": "emp2",
"data": [
{
"emp_country": "country2",
"emp_city": "city2",
"salary": [
{
"currency": "INR",
"amount": 5000
},
{
"currency": "MXN",
"amount": 200
},
{
"currency": "MXN",
"amount": 400
}
]
}
]
},
{
"id": "3",
"emp_name": "emp3",
"data": [
{
"emp_country": "country1",
"emp_city": "city1",
"salary": [
{
"currency": "MXN",
"amount": 400
}
]
}
]
},
{
"id": "4",
"emp_name": "emp4",
"data": [
{
"emp_country": "country1",
"emp_city": "city2",
"salary": [
{
"currency": "DOLLER",
"amount": 200
}
]
}
]
}
]
Expected Output:
city, country, the name should be unique and salary have max and min based on currency.
[
{
"emp_city": "city1",
"emp_country": "country1",
"emp_name": "emp1",
"emp_salary": [{
"currency": "INR",
"max": 5000,
"min": 600
},
{
"currency": "MXN",
"max": 400,
"min": 400
}]
},
{
"emp_city": "city2",
"emp_country": "country1",
"emp_name": "emp1",
"emp_salary":[ {
"currency": "DOLLER",
"max": 5000,
"min": 200
},
{
"currency": "MXN",
"max": 400,
"min": 400
}]
},
{
"emp_city": "city2",
"emp_country": "country2",
"emp_name": "emp2",
"emp_salary": [{
"currency": "INR",
"max": 5000,
"min": 5000
},
{
"currency": "MXN",
"max": 400,
"min": 200
}]
},
{
"emp_city": "city1",
"emp_country": "country1",
"emp_name": "emp3",
"emp_salary": [{
"currency": "MXN",
"max": 400,
"min": 400
}]
},
{
"emp_city": "city2",
"emp_country": "country1",
"emp_name": "emp4",
"emp_salary": [{
"currency": "DOLLER",
"max": 200,
"min": 200
}]
}
]
We can achieve the above result using an aggregation query.
$unwind - to deconstruct array of salary
$group - group by emp city, country, name, currency with min and max value of salary
$group - use another to push in emp_salary
$project - to show fields in your format
db.collection.aggregate([
{
"$unwind": {
"path": "$data"
}
},
{
"$unwind": {
"path": "$data.salary"
}
},
{
"$group": {
"_id": {
"emp_city": "$data.emp_city",
"emp_country": "$data.emp_country",
"emp_name": "$emp_name",
"currency": "$data.salary.currency",
},
"max": {
"$max": "$data.salary.amount"
},
"min": {
"$min": "$data.salary.amount"
}
}
},
{
"$group": {
"_id": {
"emp_city": "$_id.emp_city",
"emp_country": "$_id.emp_country",
"emp_name": "$_id.emp_name",
},
"emp_salary": {
"$push": {
"currency": "$_id.currency",
"min": "$min",
"max": "$max"
}
}
}
},
{
"$project": {
"_id": 0,
"emp_city": "$_id.emp_city",
"emp_country": "$_id.emp_country",
"emp_name": "$_id.emp_name",
"emp_salary": 1,
}
}
])
Mongo Playground
I'm trying to write a java JUnit test that will deploy template-defined resource groups using the java-sdk for azure.
I came across a couple examples and followed them to create this code segment:
public void azurePoC() throws Exception {
Azure azure = Azure.configure()
.withLogLevel(LogLevel.BODY)
.authenticate(new File("C:/somePath/credentials.azure"))
.withDefaultSubscription();
final ObjectMapper mapper = new ObjectMapper();
JsonNode template = mapper.readTree(new File("C:/somePath/template.json"));
Logger.report("template", template.toString());
JsonNode params = mapper.readTree(new File("C:/somePath/parameters.json"));
Logger.report("params", params.toString());
azure.deployments()
.define("myNewResource")
.withNewResourceGroup("myNewResourceGroup", Region.US_WEST2)
.withTemplate(template)
.withParameters(params)
.withMode(DeploymentMode.INCREMENTAL)
.create();
Logger.report("Request for deployment done.");
}
I have verified that the API allows me to lookup resources using azure.virtualMachines().list() method, therefore i conclude that my credentials are okay.
I am using one of the quick-start templates to for my PoC, just to see if i can deploy some resource.
My template.json file:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"type": "string",
"metadata": {
"description": "User name for the Virtual Machine."
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Password for the Virtual Machine."
}
},
"dnsLabelPrefix": {
"type": "string",
"metadata": {
"description": "Unique DNS Name for the Public IP used to access the Virtual Machine."
}
},
"ubuntuOSVersion": {
"type": "string",
"defaultValue": "16.04.0-LTS",
"allowedValues": [
"12.04.5-LTS",
"14.04.5-LTS",
"15.10",
"16.04.0-LTS"
],
"metadata": {
"description": "The Ubuntu version for the VM. This will pick a fully patched image of this given Ubuntu version."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"storageAccountName": "[concat(uniquestring(resourceGroup().id), 'salinuxvm')]",
"imagePublisher": "Canonical",
"imageOffer": "UbuntuServer",
"nicName": "myVMNic",
"addressPrefix": "10.0.0.0/16",
"subnetName": "Subnet",
"subnetPrefix": "10.0.0.0/24",
"storageAccountType": "Standard_LRS",
"publicIPAddressName": "myPublicIP",
"publicIPAddressType": "Dynamic",
"vmName": "MyUbuntuVM",
"vmSize": "Standard_A1",
"virtualNetworkName": "MyVNET",
"subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "2018-07-01",
"location": "[parameters('location')]",
"sku": {
"name": "[variables('storageAccountType')]"
},
"kind": "Storage",
"properties": {}
},
{
"apiVersion": "2018-10-01",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[parameters('location')]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[parameters('dnsLabelPrefix')]"
}
}
},
{
"apiVersion": "2018-10-01",
"type": "Microsoft.Network/virtualNetworks",
"name": "[variables('virtualNetworkName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetPrefix')]"
}
}
]
}
},
{
"apiVersion": "2018-10-01",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
"[resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},
{
"apiVersion": "2018-10-01",
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('vmName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[variables('vmSize')]"
},
"osProfile": {
"computerName": "[variables('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "[variables('imagePublisher')]",
"offer": "[variables('imageOffer')]",
"sku": "[parameters('ubuntuOSVersion')]",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage"
},
"dataDisks": [
{
"diskSizeGB": 1023,
"lun": 0,
"createOption": "Empty"
}
]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), '2016-01-01').primaryEndpoints.blob)]"
}
}
}
}
],
"outputs": {
"hostname": {
"type": "string",
"value": "[reference(variables('publicIPAddressName')).dnsSettings.fqdn]"
},
"sshCommand": {
"type": "string",
"value": "[concat('ssh ', parameters('adminUsername'), '#', reference(variables('publicIPAddressName')).dnsSettings.fqdn)]"
}
}
}
My parameters.json file:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"value": "ghuser"
},
"adminPassword": {
"value": "GEN-PASSWORD"
},
"dnsLabelPrefix": {
"value": "GEN-UNIQUE"
}
}
}
Whenever I run the application I am confronted with this exception:
com.microsoft.azure.CloudException: The request content was invalid and could not be deserialized: 'Error converting value "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#" to type 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Data.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.$schema', line 1, position 4459.'.: The request content was invalid and could not be deserialized: 'Error converting value "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#" to type 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Data.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.$schema', line 1, position 4459.'.
at com.microsoft.azure.AzureClient.createExceptionFromResponse(AzureClient.java:740)
at com.microsoft.azure.AzureClient.access$100(AzureClient.java:33)
at com.microsoft.azure.AzureClient$3.call(AzureClient.java:160)
at com.microsoft.azure.AzureClient$3.call(AzureClient.java:157)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:69)
at retrofit2.adapter.rxjava.CallArbiter.deliverResponse(CallArbiter.java:120)
at retrofit2.adapter.rxjava.CallArbiter.emitResponse(CallArbiter.java:102)
at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:46)
at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:24)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeSingle.call(OnSubscribeSingle.java:81)
at rx.internal.operators.OnSubscribeSingle.call(OnSubscribeSingle.java:27)
at rx.internal.operators.SingleToObservable.call(SingleToObservable.java:39)
at rx.internal.operators.SingleToObservable.call(SingleToObservable.java:27)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.DeferredScalarSubscriber.subscribeTo(DeferredScalarSubscriber.java:153)
at rx.internal.operators.OnSubscribeTakeLastOne.call(OnSubscribeTakeLastOne.java:32)
at rx.internal.operators.OnSubscribeTakeLastOne.call(OnSubscribeTakeLastOne.java:22)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100)
at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:230)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: retrofit2.Response.class
at rx.exceptions.OnErrorThrowable.addValueAsLastCause(OnErrorThrowable.java:118)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:73)
... 43 more
Any and all help in the matter will be greatly appreciated.
For anyone who comes across this question.
Turns out the problem was the parameter file json syntax.
The schema, parameters and version fields are redundant
this is the expected syntax using Azure Java SDK:
{
"adminUsername": {
"value": "ghuser"
},
"adminPassword": {
"value": "GEN-PASSWORD"
},
"dnsLabelPrefix": {
"value": "GEN-UNIQUE"
}
}
i have Json string like this where the function return List:
[
{
"name": "DEFAULT",
"effectiveDate": "Apr 19, 2018 3:35:31 PM",
"currencies": [
"IDR"
],
"products": [
{
"type": "BASE",
"name": "PostPaid",
"plans": [
{
"name": "postpaid-monthly-fix",
"billingPeriod": "MONTHLY",
"phases": [
{
"type": "EVERGREEN",
"prices": [
{
"currency": "IDR",
"value": 300000
}
],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": []
}
]
},
{
"name": "postpaid-monthly-trial1",
"billingPeriod": "MONTHLY",
"phases": [
{
"type": "TRIAL",
"prices": [],
"fixedPrices": [
{
"currency": "IDR",
"value": 0
}
],
"duration": {
"unit": "DAYS",
"number": 1
},
"usages": []
},
{
"type": "EVERGREEN",
"prices": [
{
"currency": "IDR",
"value": 250000
}
],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": []
}
]
},
{
"name": "postpaid-monthly-trial7",
"billingPeriod": "MONTHLY",
"phases": [
{
"type": "TRIAL",
"prices": [],
"fixedPrices": [
{
"currency": "IDR",
"value": 0
}
],
"duration": {
"unit": "DAYS",
"number": 7
},
"usages": []
},
{
"type": "EVERGREEN",
"prices": [
{
"currency": "IDR",
"value": 350000
}
],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": []
}
]
}
],
"included": [],
"available": []
},
{
"type": "BASE",
"name": "PrePaid",
"plans": [
{
"name": "prepaid-signature-item",
"billingPeriod": "NO_BILLING_PERIOD",
"phases": [
{
"type": "EVERGREEN",
"prices": [],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": [
{
"billingPeriod": "DAILY",
"tiers": [
{
"blocks": [
{
"unit": "item",
"size": "1.0",
"max": "5.0",
"prices": [
{
"currency": "IDR",
"value": 250000
}
]
}
],
"limits": [],
"fixedPrice": [],
"recurringPrice": []
}
]
}
]
}
]
}
],
"included": [],
"available": []
}
],
"priceLists": [
{
"name": "DEFAULT",
"plans": [
"postpaid-monthly-fix",
"postpaid-monthly-trial1",
"postpaid-monthly-trial7",
"prepaid-signature-item"
]
}
]
},
{
"name": "DEFAULT",
"effectiveDate": "Apr 20, 2018 3:35:31 PM",
"currencies": [
"IDR"
],
"products": [
{
"type": "BASE",
"name": "PostPaid",
"plans": [
{
"name": "postpaid-monthly-fix",
"billingPeriod": "MONTHLY",
"phases": [
{
"type": "EVERGREEN",
"prices": [
{
"currency": "IDR",
"value": 300000
}
],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": []
}
]
},
{
"name": "postpaid-monthly-trial1",
"billingPeriod": "MONTHLY",
"phases": [
{
"type": "TRIAL",
"prices": [],
"fixedPrices": [
{
"currency": "IDR",
"value": 0
}
],
"duration": {
"unit": "DAYS",
"number": 1
},
"usages": []
},
{
"type": "EVERGREEN",
"prices": [
{
"currency": "IDR",
"value": 250000
}
],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": []
}
]
},
{
"name": "postpaid-monthly-trial7",
"billingPeriod": "MONTHLY",
"phases": [
{
"type": "TRIAL",
"prices": [],
"fixedPrices": [
{
"currency": "IDR",
"value": 0
}
],
"duration": {
"unit": "DAYS",
"number": 7
},
"usages": []
},
{
"type": "EVERGREEN",
"prices": [
{
"currency": "IDR",
"value": 350000
}
],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": []
}
]
}
],
"included": [],
"available": []
},
{
"type": "BASE",
"name": "PrePaid",
"plans": [
{
"name": "prepaid-signature-item",
"billingPeriod": "NO_BILLING_PERIOD",
"phases": [
{
"type": "EVERGREEN",
"prices": [],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": [
{
"billingPeriod": "NO_BILLING_PERIOD",
"tiers": [
{
"blocks": [
{
"unit": "item",
"size": "1.0",
"max": "5.0",
"prices": [
{
"currency": "IDR",
"value": 250000
}
]
}
],
"limits": [],
"fixedPrice": [],
"recurringPrice": []
}
]
}
]
}
]
}
],
"included": [],
"available": []
}
],
"priceLists": [
{
"name": "DEFAULT",
"plans": [
"postpaid-monthly-fix",
"postpaid-monthly-trial1",
"postpaid-monthly-trial7",
"prepaid-signature-item"
]
}
]
},
{
"name": "DEFAULT",
"effectiveDate": "Apr 21, 2018 3:35:31 PM",
"currencies": [
"IDR"
],
"products": [
{
"type": "BASE",
"name": "PostPaid",
"plans": [
{
"name": "postpaid-monthly-fix",
"billingPeriod": "MONTHLY",
"phases": [
{
"type": "EVERGREEN",
"prices": [
{
"currency": "IDR",
"value": 300000
}
],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": []
}
]
},
{
"name": "postpaid-monthly-trial1",
"billingPeriod": "MONTHLY",
"phases": [
{
"type": "TRIAL",
"prices": [],
"fixedPrices": [
{
"currency": "IDR",
"value": 0
}
],
"duration": {
"unit": "DAYS",
"number": 1
},
"usages": []
},
{
"type": "EVERGREEN",
"prices": [
{
"currency": "IDR",
"value": 250000
}
],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": []
}
]
},
{
"name": "postpaid-monthly-trial7",
"billingPeriod": "MONTHLY",
"phases": [
{
"type": "TRIAL",
"prices": [],
"fixedPrices": [
{
"currency": "IDR",
"value": 0
}
],
"duration": {
"unit": "DAYS",
"number": 7
},
"usages": []
},
{
"type": "EVERGREEN",
"prices": [
{
"currency": "IDR",
"value": 350000
}
],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": []
}
]
}
],
"included": [],
"available": []
},
{
"type": "BASE",
"name": "PrePaid",
"plans": [
{
"name": "prepaid-signature-item",
"billingPeriod": "NO_BILLING_PERIOD",
"phases": [
{
"type": "EVERGREEN",
"prices": [],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": [
{
"billingPeriod": "DAILY",
"tiers": [
{
"blocks": [
{
"unit": "item",
"size": "1.0",
"max": "5.0",
"prices": [
{
"currency": "IDR",
"value": 250000
}
]
}
],
"limits": [],
"fixedPrice": [],
"recurringPrice": []
}
]
}
]
}
]
}
],
"included": [],
"available": []
}
],
"priceLists": [
{
"name": "DEFAULT",
"plans": [
"postpaid-monthly-fix",
"postpaid-monthly-trial1",
"postpaid-monthly-trial7",
"prepaid-signature-item"
]
}
]
},
{
"name": "DEFAULT",
"effectiveDate": "Apr 21, 2018 3:38:31 PM",
"currencies": [
"IDR"
],
"products": [
{
"type": "BASE",
"name": "PostPaid",
"plans": [
{
"name": "postpaid-monthly-fix",
"billingPeriod": "MONTHLY",
"phases": [
{
"type": "EVERGREEN",
"prices": [
{
"currency": "IDR",
"value": 300000
}
],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": []
}
]
},
{
"name": "postpaid-monthly-trial1",
"billingPeriod": "MONTHLY",
"phases": [
{
"type": "TRIAL",
"prices": [],
"fixedPrices": [
{
"currency": "IDR",
"value": 0
}
],
"duration": {
"unit": "DAYS",
"number": 1
},
"usages": []
},
{
"type": "EVERGREEN",
"prices": [
{
"currency": "IDR",
"value": 250000
}
],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": []
}
]
},
{
"name": "postpaid-monthly-trial7",
"billingPeriod": "MONTHLY",
"phases": [
{
"type": "TRIAL",
"prices": [],
"fixedPrices": [
{
"currency": "IDR",
"value": 0
}
],
"duration": {
"unit": "DAYS",
"number": 7
},
"usages": []
},
{
"type": "EVERGREEN",
"prices": [
{
"currency": "IDR",
"value": 350000
}
],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": []
}
]
}
],
"included": [],
"available": []
},
{
"type": "BASE",
"name": "PrePaid",
"plans": [
{
"name": "prepaid-signature-item",
"billingPeriod": "NO_BILLING_PERIOD",
"phases": [
{
"type": "EVERGREEN",
"prices": [],
"fixedPrices": [],
"duration": {
"unit": "UNLIMITED",
"number": -1
},
"usages": [
{
"billingPeriod": "DAILY",
"tiers": [
{
"blocks": [
{
"unit": "item",
"size": "1.0",
"max": "5.0",
"prices": [
{
"currency": "IDR",
"value": 250000
}
]
}
],
"limits": [],
"fixedPrice": [],
"recurringPrice": []
}
]
}
]
}
]
}
],
"included": [],
"available": []
}
],
"priceLists": [
{
"name": "DEFAULT",
"plans": [
"postpaid-monthly-fix",
"postpaid-monthly-trial1",
"postpaid-monthly-trial7",
"prepaid-signature-item"
]
}
]
}
]
where json build by this code:
String json = new Gson().toJson(price);
then i want to get single value, for example :
"plans":["postpaid-monthly-fix","postpaid-monthly-trial1","postpaid-monthly-trial7","prepaid-signature-item"]
i try with json.get("plans") but get syntax erro, any clue ?
Try the following:
String s = "[{\"name\":\"DEFAULT\",\"effectiveDate\":\"Apr 19, 2018 3:35:31 PM\",\"currencies\":[\"IDR\"],\"products\":[{\"type\":\"BASE\",\"name\":\"PostPaid\",\"plans\":[{\"name\":\"postpaid-monthly-fix\",\"billingPeriod\":\"MONTHLY\",\"phases\":[{\"type\":\"EVERGREEN\",\"prices\":[{\"currency\":\"IDR\",\"value\":300000}],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[]}]},{\"name\":\"postpaid-monthly-trial1\",\"billingPeriod\":\"MONTHLY\",\"phases\":[{\"type\":\"TRIAL\",\"prices\":[],\"fixedPrices\":[{\"currency\":\"IDR\",\"value\":0}],\"duration\":{\"unit\":\"DAYS\",\"number\":1},\"usages\":[]},{\"type\":\"EVERGREEN\",\"prices\":[{\"currency\":\"IDR\",\"value\":250000}],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[]}]},{\"name\":\"postpaid-monthly-trial7\",\"billingPeriod\":\"MONTHLY\",\"phases\":[{\"type\":\"TRIAL\",\"prices\":[],\"fixedPrices\":[{\"currency\":\"IDR\",\"value\":0}],\"duration\":{\"unit\":\"DAYS\",\"number\":7},\"usages\":[]},{\"type\":\"EVERGREEN\",\"prices\":[{\"currency\":\"IDR\",\"value\":350000}],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[]}]}],\"included\":[],\"available\":[]},{\"type\":\"BASE\",\"name\":\"PrePaid\",\"plans\":[{\"name\":\"prepaid-signature-item\",\"billingPeriod\":\"NO_BILLING_PERIOD\",\"phases\":[{\"type\":\"EVERGREEN\",\"prices\":[],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[{\"billingPeriod\":\"DAILY\",\"tiers\":[{\"blocks\":[{\"unit\":\"item\",\"size\":\"1.0\",\"max\":\"5.0\",\"prices\":[{\"currency\":\"IDR\",\"value\":250000}]}],\"limits\":[],\"fixedPrice\":[],\"recurringPrice\":[]}]}]}]}],\"included\":[],\"available\":[]}],\"priceLists\":[{\"name\":\"DEFAULT\",\"plans\":[\"postpaid-monthly-fix\",\"postpaid-monthly-trial1\",\"postpaid-monthly-trial7\",\"prepaid-signature-item\"]}]},{\"name\":\"DEFAULT\",\"effectiveDate\":\"Apr 20, 2018 3:35:31 PM\",\"currencies\":[\"IDR\"],\"products\":[{\"type\":\"BASE\",\"name\":\"PostPaid\",\"plans\":[{\"name\":\"postpaid-monthly-fix\",\"billingPeriod\":\"MONTHLY\",\"phases\":[{\"type\":\"EVERGREEN\",\"prices\":[{\"currency\":\"IDR\",\"value\":300000}],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[]}]},{\"name\":\"postpaid-monthly-trial1\",\"billingPeriod\":\"MONTHLY\",\"phases\":[{\"type\":\"TRIAL\",\"prices\":[],\"fixedPrices\":[{\"currency\":\"IDR\",\"value\":0}],\"duration\":{\"unit\":\"DAYS\",\"number\":1},\"usages\":[]},{\"type\":\"EVERGREEN\",\"prices\":[{\"currency\":\"IDR\",\"value\":250000}],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[]}]},{\"name\":\"postpaid-monthly-trial7\",\"billingPeriod\":\"MONTHLY\",\"phases\":[{\"type\":\"TRIAL\",\"prices\":[],\"fixedPrices\":[{\"currency\":\"IDR\",\"value\":0}],\"duration\":{\"unit\":\"DAYS\",\"number\":7},\"usages\":[]},{\"type\":\"EVERGREEN\",\"prices\":[{\"currency\":\"IDR\",\"value\":350000}],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[]}]}],\"included\":[],\"available\":[]},{\"type\":\"BASE\",\"name\":\"PrePaid\",\"plans\":[{\"name\":\"prepaid-signature-item\",\"billingPeriod\":\"NO_BILLING_PERIOD\",\"phases\":[{\"type\":\"EVERGREEN\",\"prices\":[],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[{\"billingPeriod\":\"NO_BILLING_PERIOD\",\"tiers\":[{\"blocks\":[{\"unit\":\"item\",\"size\":\"1.0\",\"max\":\"5.0\",\"prices\":[{\"currency\":\"IDR\",\"value\":250000}]}],\"limits\":[],\"fixedPrice\":[],\"recurringPrice\":[]}]}]}]}],\"included\":[],\"available\":[]}],\"priceLists\":[{\"name\":\"DEFAULT\",\"plans\":[\"postpaid-monthly-fix\",\"postpaid-monthly-trial1\",\"postpaid-monthly-trial7\",\"prepaid-signature-item\"]}]},{\"name\":\"DEFAULT\",\"effectiveDate\":\"Apr 21, 2018 3:35:31 PM\",\"currencies\":[\"IDR\"],\"products\":[{\"type\":\"BASE\",\"name\":\"PostPaid\",\"plans\":[{\"name\":\"postpaid-monthly-fix\",\"billingPeriod\":\"MONTHLY\",\"phases\":[{\"type\":\"EVERGREEN\",\"prices\":[{\"currency\":\"IDR\",\"value\":300000}],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[]}]},{\"name\":\"postpaid-monthly-trial1\",\"billingPeriod\":\"MONTHLY\",\"phases\":[{\"type\":\"TRIAL\",\"prices\":[],\"fixedPrices\":[{\"currency\":\"IDR\",\"value\":0}],\"duration\":{\"unit\":\"DAYS\",\"number\":1},\"usages\":[]},{\"type\":\"EVERGREEN\",\"prices\":[{\"currency\":\"IDR\",\"value\":250000}],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[]}]},{\"name\":\"postpaid-monthly-trial7\",\"billingPeriod\":\"MONTHLY\",\"phases\":[{\"type\":\"TRIAL\",\"prices\":[],\"fixedPrices\":[{\"currency\":\"IDR\",\"value\":0}],\"duration\":{\"unit\":\"DAYS\",\"number\":7},\"usages\":[]},{\"type\":\"EVERGREEN\",\"prices\":[{\"currency\":\"IDR\",\"value\":350000}],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[]}]}],\"included\":[],\"available\":[]},{\"type\":\"BASE\",\"name\":\"PrePaid\",\"plans\":[{\"name\":\"prepaid-signature-item\",\"billingPeriod\":\"NO_BILLING_PERIOD\",\"phases\":[{\"type\":\"EVERGREEN\",\"prices\":[],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[{\"billingPeriod\":\"DAILY\",\"tiers\":[{\"blocks\":[{\"unit\":\"item\",\"size\":\"1.0\",\"max\":\"5.0\",\"prices\":[{\"currency\":\"IDR\",\"value\":250000}]}],\"limits\":[],\"fixedPrice\":[],\"recurringPrice\":[]}]}]}]}],\"included\":[],\"available\":[]}],\"priceLists\":[{\"name\":\"DEFAULT\",\"plans\":[\"postpaid-monthly-fix\",\"postpaid-monthly-trial1\",\"postpaid-monthly-trial7\",\"prepaid-signature-item\"]}]},{\"name\":\"DEFAULT\",\"effectiveDate\":\"Apr 21, 2018 3:38:31 PM\",\"currencies\":[\"IDR\"],\"products\":[{\"type\":\"BASE\",\"name\":\"PostPaid\",\"plans\":[{\"name\":\"postpaid-monthly-fix\",\"billingPeriod\":\"MONTHLY\",\"phases\":[{\"type\":\"EVERGREEN\",\"prices\":[{\"currency\":\"IDR\",\"value\":300000}],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[]}]},{\"name\":\"postpaid-monthly-trial1\",\"billingPeriod\":\"MONTHLY\",\"phases\":[{\"type\":\"TRIAL\",\"prices\":[],\"fixedPrices\":[{\"currency\":\"IDR\",\"value\":0}],\"duration\":{\"unit\":\"DAYS\",\"number\":1},\"usages\":[]},{\"type\":\"EVERGREEN\",\"prices\":[{\"currency\":\"IDR\",\"value\":250000}],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[]}]},{\"name\":\"postpaid-monthly-trial7\",\"billingPeriod\":\"MONTHLY\",\"phases\":[{\"type\":\"TRIAL\",\"prices\":[],\"fixedPrices\":[{\"currency\":\"IDR\",\"value\":0}],\"duration\":{\"unit\":\"DAYS\",\"number\":7},\"usages\":[]},{\"type\":\"EVERGREEN\",\"prices\":[{\"currency\":\"IDR\",\"value\":350000}],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[]}]}],\"included\":[],\"available\":[]},{\"type\":\"BASE\",\"name\":\"PrePaid\",\"plans\":[{\"name\":\"prepaid-signature-item\",\"billingPeriod\":\"NO_BILLING_PERIOD\",\"phases\":[{\"type\":\"EVERGREEN\",\"prices\":[],\"fixedPrices\":[],\"duration\":{\"unit\":\"UNLIMITED\",\"number\":-1},\"usages\":[{\"billingPeriod\":\"DAILY\",\"tiers\":[{\"blocks\":[{\"unit\":\"item\",\"size\":\"1.0\",\"max\":\"5.0\",\"prices\":[{\"currency\":\"IDR\",\"value\":250000}]}],\"limits\":[],\"fixedPrice\":[],\"recurringPrice\":[]}]}]}]}],\"included\":[],\"available\":[]}],\"priceLists\":[{\"name\":\"DEFAULT\",\"plans\":[\"postpaid-monthly-fix\",\"postpaid-monthly-trial1\",\"postpaid-monthly-trial7\",\"prepaid-signature-item\"]}]}]\n";
JSONArray jsonArray = (JSONArray) JSONValue.parseWithException(s);
List plans = (List)((Map)((List)((Map)jsonArray.get(0)).get("priceLists")).get(0)).get("plans");
System.out.println(plans);
System.out.println(plans.get(0));
System.out.println(plans.get(1));
System.out.println(plans.get(2));
System.out.println(plans.get(3));
Output:
["postpaid-monthly-fix","postpaid-monthly-trial1","postpaid-monthly-trial7","prepaid-signature-item"]
postpaid-monthly-fix
postpaid-monthly-trial1
postpaid-monthly-trial7
prepaid-signature-item