Can Multidimensional Hash Values be inserted into InfluxDB? - influxdb

In InfluxDB, can you post multidimensional hash values to the database?
For example, this hash:
{
"field1": "value1",
"field2": {
"field2a": "value2a",
"field3a": "value3a"
}
}
If you can, how do you do this? When I try via the http admin interface, it neither errors out or returns success.

Multidimensional values are not supported by InfluxDB. Points have fields that are a set of key-value pairs. Currently, values can only be of type float, integer, boolean, or string. InfluxDB has no concept of nested key-values. The relevant source is here.
A workaround would be to store the JSON as a string literal by escaping all double quote characters (e.g. \"). Then implementing whatever functionality required in the client.
curl -h -XPOST 'http://localhost:8086/write' -d '
{
"database": "test",
"retentionPolicy": "default",
"points": [
{
"name": "json_blob",
"tags": {
"tag1": "tag-value-a",
"tag2": "tag-value-b"
},
"fields": {
"value": "{\"field1\":\"value1\",\"field2\":{\"field2a\":\"value2a\",\"field3a\":"value3a\"}}"
}
}
]
}'

Related

How to hide properties with null values in FSharp.Data JsonProvider?

This piece of code:
open FSharp.Data
type ColorProvider = JsonProvider<"""
[
{
"color": "Red",
"code": 15
},
{
"color": "Green"
}
]
""", SampleIsList=true>
let value = ColorProvider.Root(color = "Blue", code = None)
printf "%A" value
Produces this JSON:
{
"color": "Blue",
"code": null
}
I'm passing the json to an external service which doesn't handle nulls. Either it must be an integer or the whole property must be missing.
Is there a way to hide the code property when it's null?
You are using FSharp's object printing feature for generating JSON. It produces JSON-like output, but in my opinion it is not meant for that task. I'd suggest using a JSON library for that, personally I like using https://github.com/Microsoft/fsharplu/wiki/fsharplu.json for that task, as it produces beautiful JSON for Discriminate Unions.

DDMathParser: Parsing dynamic formula which contain $ to refer objects value within dictionary

I am struggling a little bit to use DDMathParser framework for expression requirement I have. I have JSON of fields & based on expressions certain fields can be set required, hidden or set the value of it.
Expressions in required tag in sample JSON are not fixed & so not getting how to achieve dynamic approach for expression.
[
{
"name": "firstName",
"value": "Ameer",
**"required": true**
},
{
"name": "lastName",
"value": "Shaikh",
**"required": "$firstName != ‘’"**
},
{
"name": "designation",
"value": "",
**"required": "$firstName == ‘Ameer’ && $lastName == ‘Shaikh’"**
},
{
"name": "location",
"value": "",
**"hidden": false**
}
]
Actually, expression in JSON contains $ to represent one of the
dictionary objects value from JSON. Wherein framework internally
treats it as a local variable.
These expressions may have different combinations as well. There may be several expression apart from "required" parameters. I need to run all relevant expressions for any change in value in UI.
EDIT
let expression = "$firstName == ‘Ameer’ && $lastName == ‘Shaikh’"
let dict = ["firstName": "Amir", "lastName": ""]
let e = try! Expression(string: expression)
let result = try! Evaluator.default.evaluate(e, substitutions: dict)
Though it should parse a correct value from JSON, I have hard coded substitutions string to at least get a breakthrough. Here, substitutions expect String & Double & give error as "Cannot convert a value of type [String: String] to expected arg type substitutions (Dcitionary).
Is there any way to pass String: String substitutions?
DDMathParser is not built to do string evaluations. It's technically possible to make it work, but it's a bit beyond the scope of the framework.
For this situation, I think you'd be better off using NSPredicate, which does allow string comparisons and variable substitutions.

Google Firebase Cloud Messaging HTTP Protocol Payload Data json key

I have problem with sending some key in data Payload to iOS device
Here's my json to send https://fcm.googleapis.com/fcm/send -> #POST
{
"time_to_live": 216000,
"registration_ids": [
"device token"
],
"content-available" : true,
"notification": {
"body": "Some msg",
"title": "title"
},
"data": {
"code":11,
"orderStatus": {
"status": 1,
"id": 5102
}
}
}
Headers in POST request:
Authorization=key=myFirebaseKey
Content-Type=application/json
Problem with key orderStatus, in client side I get this key as a String
orderStatus = "{\"id\":5102,\"status\":1}";
Can I tell Firebase to send this key as an Object?
Or all keys in data must be simple key=value keys?
I mean value only string integer etc...?
The documentation for downstream JSON message syntax says this about the key-value pairs in the data object:
The key should not be a reserved word ("from" or any word starting
with "google" or "gcm"). Do not use any of the words defined in this
table (such as collapse_key).
Values in string types are recommended. You have to convert values in
objects or other non-string data types (e.g., integers or booleans) to
string.

restassured - parsing response and searching by value

I have following REST API response:
"items":
[
{
"empid": "1234",
"name": "Santosh",
"hiredby": "Mark",
"date": "2017-01-31,00:19:41 PST",
},
{
"empid": "5678",
"name": "Kumar",
"hiredby": "Bob",
"date": "2017-01-31,08:30:31 PST"
}
]
My query is : - How do i get empid based on querying name as Kumar.
For example: I need to find "Kumar" name and get his empid. (that is, search by name and get his empid as response) I'm able to get the response and store it in Response object. but, from response object how can i traverse and query to get the required value.
Also,
I tried by retrieving as:
String name = get(REST_ENDPOINT).then().body("items.name",hasItems("Kumar")).extract().path("items.empid").toString();
when i print the response i get collection of the empid like [1234,5678], where as my expectation is to get only 5678.
Do I need to parse via JSONArray and JSONObject and iterate the response?
Please suggest.
You can use something like this
response1.jsonPath().getList("collect { it.credentials.findAll { it.credentialType == 'Ban User Name'}.credentialId }.flatten()")

RestKit JSON Mapping

I have given JSON and cannot parse partial data. It seems dictionary into dictionary:
{
"products": [
{
"id": 6796,
"title": "my title",
"description": "desc",
"code": "12345",
"valueType": "null",
"discounts": [
{
"minPrice": null,
"maxPrice": null,
"value": 20,
"avail": false
}
]
}
]
}
I am using the latest version of RESTKit but I cannot properly parse under discounts.
my RestKit settings are:
responseMapping.addAttributeMappingsFromDictionary([
"id" : "id",
"code" : "code",
"title" : "title",
"valueType" : "valueType",
"description" : "desc",
"discounts.minPrice" : "minPrice",
"discounts.maxPrice" : "maxPrice",
"discounts.value" : "value",
"discounts.avail" : "avail",
])
but all values below discounts always return Nil. What I am doing wrong?
You can't directly map using discounts.XXX because discounts is an array and you have no way to index into that array and extract a single value.
You either need to change the source JSON to compress the values out of the dictionary, or create a custom object that you can map each item in the discounts array to.
Technically you could map the whole discounts array, which would give you an array of dictionaries, that you could then unpack in the setter method, but the array of custom objects is usually a better approach.

Resources