get single value from json string - java

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

Related

Optional Properties json schema

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"] }
}
]
}

Recursively print all json elements and nested elements using gson

My program currently gets a response from an api which returns an extensive json script, usually around 400 lines or more. Within this JSON there are well over 20 elements, of which only about 2 are needed for other functions, the rest just needs to printed.
I have tried to make classes for each element but it became excessive, especially when the elements had different variations, and so i was told a recursive approach would be better suited. My current attempt involves using gson, although I find myself using instanceof in order to determine whether the next json element can be mapped using gson.
My JSON script looks as follows:
{
"id": "fox",
"metadata": {
"operation": "retrieve",
"provider": "Oxford University Press",
"schema": "RetrieveEntry"
},
"results": [
{
"id": "fox",
"language": "en-gb",
"lexicalEntries": [
{
"derivatives": [
{
"id": "foxlike",
"text": "foxlike"
}
],
"entries": [
{
"etymologies": [
"Old English, of Germanic origin; related to Dutch vos and German Fuchs"
],
"pronunciations": [
{
"audioFile": "https://audio.oxforddictionaries.com/en/mp3/fox_gb_1.mp3",
"dialects": [
"British English"
],
"phoneticNotation": "IPA",
"phoneticSpelling": "fɒks"
}
],
"senses": [
{
"definitions": [
"a carnivorous mammal of the dog family with a pointed muzzle and bushy tail, proverbial for its cunning."
],
"domainClasses": [
{
"id": "mammal",
"text": "Mammal"
}
],
"id": "m_en_gbus0384950.006",
"notes": [
{
"text": "Vulpes and three other genera, family Canidae: several species, including the red fox and the arctic fox",
"type": "technicalNote"
}
],
"semanticClasses": [
{
"id": "canid",
"text": "Canid"
}
],
"shortDefinitions": [
"carnivorous mammal"
],
"subsenses": [
{
"definitions": [
"the fur of a fox."
],
"domainClasses": [
{
"id": "mammal",
"text": "Mammal"
}
],
"id": "m_en_gbus0384950.010",
"notes": [
{
"text": "mass noun",
"type": "grammaticalNote"
}
],
"semanticClasses": [
{
"id": "fur",
"text": "Fur"
}
],
"shortDefinitions": [
"fur of fox"
]
}
],
"synonyms": [
{
"language": "en",
"text": "Reynard"
}
],
"thesaurusLinks": [
{
"entry_id": "fox",
"sense_id": "t_en_gb0006011.001"
}
]
},
{
"definitions": [
"a cunning or sly person"
],
"examples": [
{
"text": "a wily old fox"
}
],
"id": "m_en_gbus0384950.013",
"semanticClasses": [
{
"id": "disliked_person",
"text": "Disliked_Person"
}
],
"shortDefinitions": [
"cunning or sly person"
]
},
{
"definitions": [
"a sexually attractive woman."
],
"id": "m_en_gbus0384950.015",
"regions": [
{
"id": "north_american",
"text": "North_American"
}
],
"registers": [
{
"id": "informal",
"text": "Informal"
}
],
"semanticClasses": [
{
"id": "attractive_female",
"text": "Attractive_Female"
}
],
"shortDefinitions": [
"sexually attractive woman"
]
}
]
}
],
"language": "en-gb",
"lexicalCategory": {
"id": "noun",
"text": "Noun"
},
"text": "fox"
},
{
"derivatives": [
{
"id": "foxlike",
"text": "foxlike"
}
],
"entries": [
{
"grammaticalFeatures": [
{
"id": "transitive",
"text": "Transitive",
"type": "Subcategorization"
}
],
"pronunciations": [
{
"audioFile": "https://audio.oxforddictionaries.com/en/mp3/fox_gb_1.mp3",
"dialects": [
"British English"
],
"phoneticNotation": "IPA",
"phoneticSpelling": "fɒks"
}
],
"senses": [
{
"definitions": [
"baffle or deceive (someone)"
],
"examples": [
{
"text": "the abbreviation foxed me completely"
}
],
"id": "m_en_gbus0384950.017",
"registers": [
{
"id": "informal",
"text": "Informal"
}
],
"shortDefinitions": [
"baffle or deceive"
],
"subsenses": [
{
"definitions": [
"behave in a cunning or sly way"
],
"examples": [
{
"text": "to his mind everybody was dodging and foxing"
}
],
"id": "m_en_gbus0384950.023",
"notes": [
{
"text": "no object",
"type": "grammaticalNote"
}
],
"registers": [
{
"id": "dated",
"text": "Dated"
}
],
"shortDefinitions": [
"behave in cunning or sly way"
]
}
],
"synonyms": [
{
"language": "en",
"text": "baffle"
},
{
"language": "en",
"text": "bewilder"
},
{
"language": "en",
"text": "mystify"
},
{
"language": "en",
"text": "bemuse"
},
{
"language": "en",
"text": "perplex"
},
{
"language": "en",
"text": "puzzle"
},
{
"language": "en",
"text": "confuse"
},
{
"language": "en",
"text": "confound"
},
{
"language": "en",
"text": "nonplus"
},
{
"language": "en",
"text": "disconcert"
},
{
"language": "en",
"text": "throw"
},
{
"language": "en",
"text": "throw off balance"
},
{
"language": "en",
"text": "disorientate"
},
{
"language": "en",
"text": "take aback"
},
{
"language": "en",
"text": "set thinking"
}
],
"thesaurusLinks": [
{
"entry_id": "flummox",
"sense_id": "t_en_gb0005828.001"
}
]
}
]
}
],
"language": "en-gb",
"lexicalCategory": {
"id": "verb",
"text": "Verb"
},
"text": "fox"
}
],
"type": "headword",
"word": "fox"
},
{
"id": "Fox",
"language": "en-gb",
"lexicalEntries": [
{
"entries": [
{
"inflections": [
{
"grammaticalFeatures": [
{
"id": "plural",
"text": "Plural",
"type": "Number"
}
],
"inflectedForm": "Fox"
}
],
"pronunciations": [
{
"audioFile": "https://audio.oxforddictionaries.com/en/mp3/fox_gb_1.mp3",
"dialects": [
"British English"
],
"phoneticNotation": "IPA",
"phoneticSpelling": "fɒks"
}
],
"senses": [
{
"definitions": [
"a member of a North American people formerly living in southern Wisconsin, and now mainly in Iowa, Nebraska, and Kansas."
],
"domainClasses": [
{
"id": "people",
"text": "People"
},
{
"id": "amerindian",
"text": "Amerindian"
}
],
"id": "m_en_gbus0384960.006",
"semanticClasses": [
{
"id": "amerindian",
"text": "Amerindian"
}
],
"shortDefinitions": [
"member of North American people"
]
},
{
"definitions": [
"the Algonquian language of the Fox, now almost extinct."
],
"domainClasses": [
{
"id": "language",
"text": "Language"
},
{
"id": "amerindian",
"text": "Amerindian"
}
],
"id": "m_en_gbus0384960.010",
"notes": [
{
"text": "mass noun",
"type": "grammaticalNote"
}
],
"semanticClasses": [
{
"id": "amerindian_language",
"text": "Amerindian_Language"
}
],
"shortDefinitions": [
"Algonquian language of Fox, now extinct"
]
}
]
}
],
"language": "en-gb",
"lexicalCategory": {
"id": "noun",
"text": "Noun"
},
"text": "Fox"
},
{
"entries": [
{
"pronunciations": [
{
"audioFile": "https://audio.oxforddictionaries.com/en/mp3/fox_gb_1.mp3",
"dialects": [
"British English"
],
"phoneticNotation": "IPA",
"phoneticSpelling": "fɒks"
}
],
"senses": [
{
"definitions": [
"relating to the Fox or their language."
],
"domainClasses": [
{
"id": "amerindian",
"text": "Amerindian"
}
],
"id": "m_en_gbus0384960.013",
"shortDefinitions": [
"relating to Fox or their language"
]
}
]
}
],
"language": "en-gb",
"lexicalCategory": {
"id": "adjective",
"text": "Adjective"
},
"text": "Fox"
}
],
"type": "headword",
"word": "Fox"
}
],
"word": "fox"
}
If there are any edits I should make to my question please let me know, this is my first question here. Thanks for any help.
EDIT:
The output needs to be formatted neatly, so basically it must be line separated and should be displayed in an easy to read manner, but as well as this, some elements, such as synonyms, need to have their words hyperlinked so they must be identified separately. Hope this helps

How to get Max and Min Value in MongoDB based on specific key?

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

How to filter ElasticSearch results basis the field value?

Below is my example search response with 4 results retrieved.
{
"took": 13,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 0.41753215,
"hits": [
{
"_index": "google_a804f89b-d32e-426a-a79a-ea83d65c98ea",
"_type": "viz_dashlet",
"_id": "/shared/Report_google_Shared",
"_score": 0.41753215,
"fields": {
"lastModified": [
1461738428007
],
"dir": [
"/shared"
],
"filename": [
"Report_google_Shared"
]
},
"highlight": {
"filename": [
"Report_google_Shared"
]
}
},
{
"_index": "google_a804f89b-d32e-426a-a79a-ea83d65c98ea",
"_type": "viz_dashlet",
"_id": "/shared/Report_Gmail_Shared",
"_score": 0.41753215,
"fields": {
"lastModified": [
1461738618676
],
"dir": [
"/shared"
],
"filename": [
"Report_Gmail_Shared"
]
},
"highlight": {
"filename": [
"Report_Gmail_Shared"
]
}
},
{
"_index": "google_a804f89b-d32e-426a-a79a-ea83d65c98ea",
"_type": "viz_dashlet",
"_id": "/private/hitesh/Report_Gmail_Private",
"_score": 0.1883173,
"fields": {
"lastModified": [
1461738629888
],
"dir": [
"/private/hitesh"
],
"filename": [
"Report_Gmail_Private"
]
},
"highlight": {
"filename": [
"Report_Gmail_Private"
]
}
},
{
"_index": "google_a804f89b-d32e-426a-a79a-ea83d65c98ea",
"_type": "viz_dashlet",
"_id": "/private/dholaria/Report_google_Private",
"_score": 0.1883173,
"fields": {
"lastModified": [
1461738451720
],
"dir": [
"/private/dholaria"
],
"filename": [
"Report_google_Private"
]
},
"highlight": {
"filename": [
"Report_google_Private"
]
}
}
]
}
}
Now, I want to filter the above search results basis the specific "dir" field value as per the below criteria.
Include the search result in the response if and only if:
If "dir" field value equals to either of: "/shared" or "/private/hitesh"
Else if "dir" field value starts with either of: "/shared/" or
"/private/hitesh/"
How can I achieve the above functionality in ElasticSearch?
PS: Below is my example mapping.
{
"google_a804f89b-d32e-426a-a79a-ea83d65c98ea": {
"mappings": {
"viz_dashlet": {
"properties": {
"charts": {
"type": "string",
"index_analyzer": "report_index_analyzer",
"search_analyzer": "report_search_analyzer",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"columnLabels": {
"type": "string",
"index_analyzer": "report_index_analyzer",
"search_analyzer": "report_search_analyzer",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"columnNames": {
"type": "string",
"index_analyzer": "report_index_analyzer",
"search_analyzer": "report_search_analyzer",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"creator": {
"type": "string",
"index_analyzer": "report_index_analyzer",
"search_analyzer": "report_search_analyzer",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"dimensions": {
"type": "string",
"index_analyzer": "report_index_analyzer",
"search_analyzer": "report_search_analyzer",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"dir": {
"type": "string",
"index_analyzer": "report_index_analyzer",
"search_analyzer": "report_search_analyzer",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"expressions": {
"type": "string",
"index_analyzer": "report_index_analyzer",
"search_analyzer": "report_search_analyzer",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"filename": {
"type": "string",
"index_analyzer": "whitespace_index",
"search_analyzer": "whitespace_search",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"lastModified": {
"type": "date",
"format": "date_hour_minute_second"
},
"measures": {
"type": "string",
"index_analyzer": "report_index_analyzer",
"search_analyzer": "report_search_analyzer",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"promptFilters": {
"type": "string",
"index_analyzer": "report_index_analyzer",
"search_analyzer": "report_search_analyzer",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
}
Try this query:
{
"query": {
"bool": {
"should": [
{
"term": {
"dir.raw": {
"value": "/shared"
}
}
},
{
"term": {
"dir.raw": {
"value": "/private/hitesh"
}
}
},
{
"match_phrase_prefix": {
"dir.raw": "/shared"
}
},
{
"match_phrase_prefix": {
"dir.raw": "/private/hitesh"
}
}
]
}
}
}

Category Search using Foursquare returns wrong Category

I'm doing a category search for food but I'm getting things like Bridges back. Can somebody please verify I'm structuring the URL correctly and if so, possibly point out what I'm doing wrong?
Thank you so much in advance.
URL (blocked out the sensitive stuff like client id and secret):
https://api.foursquare.com/v2/venues/search?client_id=PUT_YOUR_CLIENT_ID_HERE&client_secret=PUT_YOUR_CLIENT_SECRET_HERE&v=20140714&ll=40.7,-74&radius=1000&category=4d4b7105d754a06374d81259
The category ID I'm using is from foursquare's website. It's the ID for 'Food'
You can see the list of IDs Right Here
Here's my response in json (edited for size):
{
"meta": {
"code": 200
},
"response": {
"venues": [
{
"id": "430d0a00f964a5203e271fe3",
"name": "Brooklyn Bridge Park",
"contact": {
"phone": "2128033822",
"formattedPhone": "(212) 803-3822",
"twitter": "nycparks",
"facebook": "104475634308",
"facebookUsername": "BartowPell",
"facebookName": "Bartow-Pell Mansion Museum"
},
"location": {
"address": "Main St",
"crossStreet": "Plymouth St",
"lat": 40.70227697066692,
"lng": -73.9965033531189,
"distance": 389,
"postalCode": "11201",
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"Main St (Plymouth St)",
"Brooklyn, NY 11201",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d163941735",
"name": "Park",
"pluralName": "Parks",
"shortName": "Park",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/parks_outdoors\/park_",
"suffix": ".png"
},
"primary": true
}
],
"verified": true,
"stats": {
"checkinsCount": 28131,
"usersCount": 17548,
"tipCount": 177
},
"url": "http:\/\/nyc.gov\/parks",
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 15,
"summary": "15 people are checked in here",
"groups": [
{
"type": "others",
"name": "Other people here",
"count": 15,
"items": [
]
}
]
},
"referralId": "v-1429381004"
},
{
"id": "4a43bcb7f964a520bba61fe3",
"name": "Brooklyn Bridge",
"contact": {
"twitter": "nyc_dot",
"facebook": "166279802886",
"facebookUsername": "NYCDOT",
"facebookName": "NYC DOT"
},
"location": {
"address": "Brooklyn Bridge",
"lat": 40.705953265881305,
"lng": -73.99656772613525,
"distance": 723,
"postalCode": "10038",
"cc": "US",
"city": "New York",
"state": "NY",
"country": "United States",
"formattedAddress": [
"Brooklyn Bridge",
"New York, NY 10038",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d1df941735",
"name": "Bridge",
"pluralName": "Bridges",
"shortName": "Bridge",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/parks_outdoors\/bridge_",
"suffix": ".png"
},
"primary": true
}
],
"verified": true,
"stats": {
"checkinsCount": 120787,
"usersCount": 67456,
"tipCount": 534
},
"url": "http:\/\/www.nyc.gov\/dot",
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 18,
"summary": "18 people are checked in here",
"groups": [
{
"type": "others",
"name": "Other people here",
"count": 18,
"items": [
]
}
]
},
"storeId": "",
"referralId": "v-1429381004"
},
{
"id": "51eabef6498e10cf3aea7942",
"name": "Brooklyn Bridge Park - Pier 2",
"contact": {
},
"location": {
"address": "Furman St",
"crossStreet": "Brooklyn Bridge Park Greenway",
"lat": 40.69956454780675,
"lng": -73.99835740533105,
"distance": 146,
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"Furman St (Brooklyn Bridge Park Greenway)",
"Brooklyn, NY",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d163941735",
"name": "Park",
"pluralName": "Parks",
"shortName": "Park",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/parks_outdoors\/park_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 1508,
"usersCount": 1161,
"tipCount": 10
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "3fd66200f964a520daf11ee3",
"name": "South Street Seaport",
"contact": {
"phone": "2127327678",
"formattedPhone": "(212) 732-7678",
"twitter": "theseaport"
},
"location": {
"address": "South St",
"crossStreet": "Pier 17",
"lat": 40.70566047104496,
"lng": -74.00287628173828,
"distance": 675,
"postalCode": "10038",
"cc": "US",
"city": "New York",
"state": "NY",
"country": "United States",
"formattedAddress": [
"South St (Pier 17)",
"New York, NY 10038",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d1e0941735",
"name": "Harbor \/ Marina",
"pluralName": "Harbors \/ Marinas",
"shortName": "Harbor \/ Marina",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/parks_outdoors\/harbor_",
"suffix": ".png"
},
"primary": true
}
],
"verified": true,
"stats": {
"checkinsCount": 45850,
"usersCount": 29726,
"tipCount": 180
},
"url": "http:\/\/www.southstreetseaport.com",
"specials": {
"count": 0,
"items": [
]
},
"events": {
"count": 1,
"summary": "Hornblower",
"items": [
{
"id": "550a2152498e6adfd409dfa4",
"name": "Hornblower",
"categories": [
],
"allDay": true,
"date": 1429345800,
"timeZone": "America\/New_York",
"text": "",
"url": "http:\/\/www.voiceplaces.com\/new-york\/hornblower-4897577-e",
"images": [
],
"provider": {
"name": "Village Voice",
"iconUrl": {
"prefix": "https:\/\/playfoursquare.s3.amazonaws.com\/events\/images\/partners\/villagevoice\/",
"sizes": [
20,
40
],
"name": "\/logo.png"
},
"urlText": "more info"
},
"stats": {
"checkinsCount": 0,
"usersCount": 0
}
}
]
},
"hereNow": {
"count": 5,
"summary": "5 people are checked in here",
"groups": [
{
"type": "others",
"name": "Other people here",
"count": 5,
"items": [
]
}
]
},
"venuePage": {
"id": "59071427"
},
"storeId": "",
"referralId": "v-1429381004"
},
{
"id": "42377700f964a52024201fe3",
"name": "Brooklyn Heights Promenade",
"contact": {
},
"location": {
"address": "Columbia Heights",
"crossStreet": "btwn Remsen & Orange",
"lat": 40.69829137715981,
"lng": -73.99663209915161,
"distance": 342,
"postalCode": "11201",
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"Columbia Heights (btwn Remsen & Orange)",
"Brooklyn, NY 11201",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d163941735",
"name": "Park",
"pluralName": "Parks",
"shortName": "Park",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/parks_outdoors\/park_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 18073,
"usersCount": 8755,
"tipCount": 138
},
"url": "http:\/\/nyharborparks.org\/visit\/brhe.html",
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "53ff2935498e161412b3e871",
"name": "Brooklyn Bridge Park - Pier 2 Yoga Court",
"contact": {
},
"location": {
"lat": 40.700111,
"lng": -73.999185,
"distance": 69,
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"Brooklyn, NY",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d102941735",
"name": "Yoga Studio",
"pluralName": "Yoga Studios",
"shortName": "Yoga Studio",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/shops\/gym_yogastudio_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 6,
"usersCount": 3,
"tipCount": 0
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "4f2c1bbae4b0ccfb1d99b510",
"name": "kk hair salon",
"contact": {
},
"location": {
"lat": 40.69956588745117,
"lng": -74.00108337402344,
"distance": 103,
"cc": "US",
"state": "New York",
"country": "United States",
"formattedAddress": [
"New York",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d110951735",
"name": "Salon \/ Barbershop",
"pluralName": "Salons \/ Barbershops",
"shortName": "Salon \/ Barbershop",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/shops\/salon_barber_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 1,
"usersCount": 1,
"tipCount": 0
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "540ca09f498e9d0f44e40791",
"name": "Smorgasburg at Brooklyn Bridge Park - Pier 2",
"contact": {
"twitter": "bkflea"
},
"location": {
"address": "Pier 2 (at Brooklyn Bridge Park)",
"lat": 40.69938593942123,
"lng": -73.99699733176632,
"distance": 262,
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"Pier 2 (at Brooklyn Bridge Park)",
"Brooklyn, NY",
"United States"
]
},
"categories": [
{
"id": "53e0feef498e5aac066fd8a9",
"name": "Street Food Gathering",
"pluralName": "Street Food Gatherings",
"shortName": "Street Food Gathering",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/food\/streetfood_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 545,
"usersCount": 523,
"tipCount": 6
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "3fd66200f964a520e9e81ee3",
"name": "Grimaldi's Pizzeria",
"contact": {
"phone": "7188584300",
"formattedPhone": "(718) 858-4300",
"twitter": "grimaldisnyc"
},
"location": {
"address": "1 Front St",
"crossStreet": "at Cadman Plaza W",
"lat": 40.70250515261926,
"lng": -73.9933359887217,
"distance": 627,
"postalCode": "11201",
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"1 Front St (at Cadman Plaza W)",
"Brooklyn, NY 11201",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d1ca941735",
"name": "Pizza Place",
"pluralName": "Pizza Places",
"shortName": "Pizza",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/food\/pizza_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 21973,
"usersCount": 18381,
"tipCount": 459
},
"url": "http:\/\/www.grimaldis.com",
"hasMenu": true,
"menu": {
"type": "Menu",
"label": "Menu",
"anchor": "View Menu",
"url": "https:\/\/foursquare.com\/v\/grimaldis-pizzeria\/3fd66200f964a520e9e81ee3\/menu",
"mobileUrl": "https:\/\/foursquare.com\/v\/3fd66200f964a520e9e81ee3\/device_menu"
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "4c34a57da0ced13a9379186e",
"name": "Under The Brooklyn Bridge",
"contact": {
"twitter": "nyc_dot",
"facebook": "166279802886",
"facebookUsername": "NYCDOT",
"facebookName": "NYC DOT"
},
"location": {
"address": "Brooklyn Bridge",
"crossStreet": "FDR Dr",
"lat": 40.703475724581324,
"lng": -73.99405334200495,
"distance": 633,
"postalCode": "11201",
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"Brooklyn Bridge (FDR Dr)",
"Brooklyn, NY 11201",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d165941735",
"name": "Scenic Lookout",
"pluralName": "Scenic Lookouts",
"shortName": "Scenic Lookout",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/parks_outdoors\/sceniclookout_",
"suffix": ".png"
},
"primary": true
}
],
"verified": true,
"stats": {
"checkinsCount": 7406,
"usersCount": 5831,
"tipCount": 31
},
"url": "http:\/\/www.nyc.gov\/dot",
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "4cb92bdc7148f04d9336d5ab",
"name": "Livys apartment !",
"contact": {
},
"location": {
"address": "95 Wall St",
"crossStreet": "Water st",
"lat": 40.700249,
"lng": -74.001442,
"distance": 124,
"postalCode": "10005",
"cc": "US",
"city": "New York",
"state": "NY",
"country": "United States",
"formattedAddress": [
"95 Wall St (Water st)",
"New York, NY 10005",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d1a3941735",
"name": "College Residence Hall",
"pluralName": "College Residence Halls",
"shortName": "Residence Hall",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/education\/residencehall_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 1,
"usersCount": 1,
"tipCount": 0
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "4c5435bf4623be9a62ee66f2",
"name": "Brooklyn Bridge Park - Pier 4",
"contact": {
},
"location": {
"address": "214 Furman St",
"crossStreet": "Montague St",
"lat": 40.69662731765942,
"lng": -73.99846644034649,
"distance": 397,
"postalCode": "11201",
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"214 Furman St (Montague St)",
"Brooklyn, NY 11201",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d163941735",
"name": "Park",
"pluralName": "Parks",
"shortName": "Park",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/parks_outdoors\/park_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 1196,
"usersCount": 945,
"tipCount": 3
},
"url": "http:\/\/www.brooklynbridgepark.org\/the-park\/future-park\/pier-4",
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "5054eb43e4b04ed4f0dd1b30",
"name": "La cabana",
"contact": {
},
"location": {
"lat": 40.69875,
"lng": -73.99953,
"distance": 144,
"cc": "US",
"state": "New York",
"country": "United States",
"formattedAddress": [
"New York",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d154941735",
"name": "Cuban Restaurant",
"pluralName": "Cuban Restaurants",
"shortName": "Cuban",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/food\/cuban_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 4,
"usersCount": 4,
"tipCount": 1
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
},
{
"id": "4ae62580f964a52011a521e3",
"name": "Danish Seamen's Church",
"contact": {
},
"location": {
"address": "102 Willow St",
"lat": 40.698023159650134,
"lng": -73.99568889745463,
"distance": 425,
"postalCode": "11201",
"cc": "US",
"city": "Brooklyn",
"state": "NY",
"country": "United States",
"formattedAddress": [
"102 Willow St",
"Brooklyn, NY 11201",
"United States"
]
},
"categories": [
{
"id": "4bf58dd8d48988d132941735",
"name": "Church",
"pluralName": "Churches",
"shortName": "Church",
"icon": {
"prefix": "https:\/\/ss3.4sqi.net\/img\/categories_v2\/building\/religious_church_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 106,
"usersCount": 71,
"tipCount": 0
},
"specials": {
"count": 0,
"items": [
]
},
"hereNow": {
"count": 0,
"summary": "Nobody here",
"groups": [
]
},
"referralId": "v-1429381004"
}
],
"confident": true
}
}
Please check foursquare venues search parameters correctly, you used "category" parameter but the correct parameter is "categoryId" (not categoryid). So you should change your url to:
https://api.foursquare.com/v2/venues/search?client_id=PUT_YOUR_CLIENT_ID_HERE&client_secret=PUT_YOUR_CLIENT_SECRET_HERE&v=20140714&ll=40.7,-74&radius=1000&categoryId=4d4b7105d754a06374d81259

Categories

Resources