I am using Retrofit 2 as a REST client for my project. I am having issues with converting date strings in JSON responses to Java java.util.Date objects. The response that I am getting from the API is of the following format:
[
{
"id": "2",
"date": "2017-04-26",
"description": "test",
"created_at": "2017-04-26 05:54:27",
"updated_at": "2017-04-26 05:54:27"
}
]
I want to convert the date value to a java.util.Date object. How can I do the conversion? Any help would be greatly appreciated.
Related
I want to fetch some dynamic id in the below given json file using JSON path finder in npm package.
Sample.json
[
{
"4787843417861749370": [
{
"type": "Fast delivery",
"subtype": "verizon",
"status": "Dispatched",
"reason": "null",
"currency_code": "USD"
}
],
"1502698381711920904": [
{
"type": "Normal delivery",
"subtype": "Cisco fiber",
"status": "Added Cart",
"reason": "null",
"currency_code": "USD"
}
]
}
]
Output (The below are dynamic id from the above sample. json file):
[4787843417861749370,1502698381711920904]
I have the similar type of the json file which contains n number of dynamic id as JSON sub array. Can someone help me to fetch all these dynamic array from the json file as like above?
You can use the jsonpath-plus library and use ~ (for grabbing property names of matching items (as array))
Try the browser demo : https://jsonpath-plus.github.io/JSONPath/demo/
$.*.*~
I have out form one of the tasks in Logic App:
{
"headers": {
"Connection": "close",
"Content-Type": "application/json"
},
"body": {
"systemAlertId": "....",
"endTimeUtc": null,
"entities": [
{
"$id": "us_1",
"hostName": "...",
"azureID": "someID",
"type": "host"
},
{
"$id": "us_2",
"address": "fwdedwedwedwed",
"location": {
"countryCode": "",
},
"type": "ip"
},
],
}
}
I need initialize some variable named resourceID that contains value someID which is read from above example.
Value someID will always be found in the first member of Entities array, in that case I guess need to use function first
Any idea how expression of Initial variable should look?
Thanks
Considering the mentioned data you are receiving from Http trigger, I have used Parse JSON in order to get the inner values of the mentioned JSON. Here is how you can do it.
and now you can initialize the resourceID using 'Initialise variable' connector and set its value to azureID as per your requirement.
Have a look at the Parse JSON action.
To reference or access properties in JavaScript Object Notation (JSON) content, you can create user-friendly fields or tokens for those properties by using the Parse JSON action. That way, you can select those properties from the dynamic content list when you specify inputs for your logic app. For this action, you can either provide a JSON schema or generate a JSON schema from your sample JSON content or payload.
With the information in the JSON available in an object, you can more easily access it.
I take AVRO bytes from Kafka and deserialize them.
But I get strange output because of decimal value and I cannot work with them next (for example turn into json or insert into DB):
import avro.schema, json
from avro.io import DatumReader, BinaryDecoder
# only needed part of schemaDict
schemaDict = {
"name": "ApplicationEvent",
"type": "record",
"fields": [
{
"name": "desiredCreditLimit",
"type": [
"null",
{
"type": "bytes",
"logicalType": "decimal",
"precision": 14,
"scale": 2
}
],
"default": null
}
]
}
schema_avro = avro.schema.parse(json.dumps(schemaDict))
reader = DatumReader(schema_avro_io)
decoder = BinaryDecoder(data) #data - bynary data from kafka
event_dict = reader.read(decoder)
print (event_dict)
#{'desiredCreditLimit': Decimal('100000.00')}
print (json.dumps(event_dict))
#TypeError: Object of type Decimal is not JSON serializable
I tried to use avro_json_serializer, but got error: "AttributeError: 'decimal.Decimal' object has no attribute 'decode'".
And because of this "Decimal" in dictionary I cannot insert values to DB too.
Also tried to use fastavro library, but I couldnot deserealize message, as I understand because sereliazation done without fastavro.
I am using jmeter 5.1 in windows 10, in my jmeter test plan i am reading json data from file, after reading, i am using log.info ${sdata} to log the messages, but the output is converted the braces { to square bracket [, could someone tell me what's wrong.
Below is the data which the json file contains
{"name":"Foo Bar","year":"2018","timestamp":"2018-03-08T00:00:00","tags":["person","employee"],"grade":3.14}
{
"name": "Foo Bar",
"year": "2018",
"timestamp": "2018-03-08T00:00:00",
"tags": [
"person",
"employee"
],
"grade": 3.14
}
Below is the line which i have in JSR223 Prepocessor to read the file and log it in info
def sdata = new groovy.json.JsonSlurper().parseText(new File("data.json").text)
log.info "$sdata"
And below is the output of log.info
["name":"Foo Bar","year":"2018","timestamp":"2018-03-08T00:00:00","tags":["person","employee"],"grade":3.14]
[
"name": "Foo Bar",
"year": "2018",
"timestamp": "2018-03-08T00:00:00",
"tags": [
"person",
"employee"
],
"grade": 3.14
]
In the above output, the braces { got replaced to square bracket [
Please help
This happens because you're basically printing a textual representation of LazyMap
If you want to see the same JSON as in the input you should create a JsonBuilder class instance and pass the "slurped" object to it.
Change this line:
log.info "$sdata"
to this one:
log.info(new groovy.json.JsonBuilder(sdata).toPrettyString())
More information:
Apache Groovy: Parsing and producing JSON
Apache Groovy - Why and How You Should Use It
In Azure logic app how to convert xml to json or json to xml based on the requirement.
The data is dynamic i,e they can be in any format. And xpath expression is required to get the required node.
The functions that you said are the correct ones, here is an example to get an xpath value from an input converted in xml:
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "xpathValue",
"type": "String",
"value": "#xpath(xml(body('Get_blob_content_using_path')), 'string(/*[local-name()=\"Part\" and namespace-uri()=\"\"])')"
}
]
},