Here is my json:
[
{
"id": "7250078e-5fbf-43d7-9c67-94b88fbf44d8",
"priority": 0,
"httpRequest": {
"method": "POST",
"path": "/catalog-data-rest/oid/search.xml",
"headers": {
"Host": [
"preproduccio.gcatalegs.isisscat.intranet.gencat.cat:8443"
],
"Authorization": [
"Basic VVNVTVBJVFNUOkJ4c2w3MjU5"
],
"User-Agent": [
"curl/7.58.0"
],
"Accept": [
"*/*"
],
"Content-Type": [
"text/html; charset=utf-8"
],
"Content-Length": [
"94"
]
},
"keepAlive": true,
"secure": true,
"body": {
"type": "STRING",
"string": "<request><oid>2.16.724.4.402</oid><startIndex>1</startIndex><pageSize>100</pageSize></request>",
"rawBytes": "PHJlcXVlc3Q+PG9pZD4yLjE2LjcyNC40LjQwMjwvb2lkPjxzdGFydEluZGV4PjE8L3N0YXJ0SW5kZXg+PHBhZ2VTaXplPjEwMDwvcGFnZVNpemU+PC9yZXF1ZXN0Pg==",
"contentType": "text/html; charset=utf-8"
}
},
"httpResponse": {
"statusCode": 200,
"reasonPhrase": "OK",
"headers": {
"Date": [
"Tue, 20 Jul 2021 11:07:40 GMT"
],
"X-Powered-By": [
"Servlet/3.0"
],
"X-Content-Type-Options": [
"nosniff"
],
"X-XSS-Protection": [
"1; mode=block"
],
"Cache-Control": [
"no-cache, no-store, max-age=0, must-revalidate"
],
"Pragma": [
"no-cache"
],
"Expires": [
"0"
],
"Strict-Transport-Security": [
"max-age=31536000 ; includeSubDomains"
],
"X-Frame-Options": [
"DENY"
],
"Set-Cookie": [
"JSESSIONID=0000r6GgpYaB7bQiXRaS8zB8qw8:19pp48tgo; Path=/; HttpOnly"
],
"Keep-Alive": [
"timeout=10, max=100"
],
"Connection": [
"Keep-Alive"
],
"Content-Type": [
"application/xml"
],
"Content-Language": [
"en-US"
],
"content-length": [
"29089"
]
},
"cookies": {
"JSESSIONID": "0000r6GgpYaB7bQiXRaS8zB8qw8:19pp48tgo"
},
"body": {
"type": "XML",
"xml": "string-value",
"rawBytes": "string-value",
"contentType": "application/xml"
}
},
"times": {
"remainingTimes": 1
},
"timeToLive": {
"unlimited": true
}
}
]
I need to remove and pick following fields:
From .httpRequest I need to REMOVE:
.httpRequest.headers
.httpRequest.keepAlive
.httpRequest.secure
.httpRequest.body.rawBytes
Desired result:
"httpRequest": {
"method": "POST",
"path": "/catalog-data-rest/oid/search.xml",
"body": {
"type": "STRING",
"string": "<request><oid>2.16.724.4.402</oid><startIndex>1</startIndex><pageSize>100</pageSize></request>",
"contentType": "text/html; charset=utf-8"
}
}
From .httpResponse I need to PICK:
.httpResponse.statusCode
.httpResponse.reasonPhrase
.httpResponse.headers.Content-Type
.httpResponse.headers.content-lenght
From .httpResponse I need to REMOVE:
.httpResponse.body.rawBytes
Desired result would be:
"httpResponse": {
"statusCode": 200,
"reasonPhrase": "OK",
"headers": {
"Content-Type": [
"application/xml"
],
"content-length": [
"29089"
]
},
"body": {
"type": "XML",
"xml": "string-value",
"contentType": "application/xml"
}
}
So my final json would be:
[
{
"httpRequest": {
"method": "POST",
"path": "/catalog-data-rest/oid/search.xml",
"body": {
"type": "STRING",
"string": "<request><oid>2.16.724.4.402</oid><startIndex>1</startIndex><pageSize>100</pageSize></request>",
"contentType": "text/html; charset=utf-8"
}
},
"httpResponse": {
"statusCode": 200,
"reasonPhrase": "OK",
"headers": {
"Content-Type": [
"application/xml"
],
"content-length": [
"29089"
]
},
"body": {
"type": "XML",
"xml": "string-value",
"contentType": "application/xml"
}
}
}
]
I hope I've explained so well.
Up to now I've able to get this demo
Create a fresh object (using {}) when you want to pick, and use del when you want to remove.
map({
"httpRequest": (
.httpRequest |
del(.headers, .keepAlive, .secure, .body.rawBytes)
),
"httpResponse": (
.httpResponse |
del(.body.rawBytes) |
{
statusCode,
reasonPhrase,
"headers": {
"Content-Type": .headers."Content-Type",
"Content-Length": .headers."content-length"
},
body
}
)
})
jqplay
The issue with both this solution and the previously-posted one is that HTTP headers are case-insensitive, so I don't think .headers."Content-Type" and .headers."content-length" will always work. Adjust as necessary.
Here is one way you could do it:
parse.jq
# We are only interested in the request and response objects
.[] | [ { httpRequest, httpResponse } ] |
# Delete unwanted paths
del(
.[].httpRequest.headers,
.[].httpRequest.keepAlive,
.[].httpRequest.secure,
.[].httpRequest.body.rawBytes,
.[].httpResponse.body.rawBytes
) |
# Reshape the httpResponse object
.[].httpResponse |=
(
{
statusCode,
reasonPhrase,
"headers" : {
"Content-Type" : .headers."Content-Type",
"content-length" : .headers."content-length"
},
body
}
)
Run it like this:
jq -f parse.jq infile.json
Output:
[
{
"httpRequest": {
"method": "POST",
"path": "/catalog-data-rest/oid/search.xml",
"body": {
"type": "STRING",
"string": "<request><oid>2.16.724.4.402</oid><startIndex>1</startIndex><pageSize>100</pageSize></request>",
"contentType": "text/html; charset=utf-8"
}
},
"httpResponse": {
"statusCode": 200,
"reasonPhrase": "OK",
"headers": {
"Content-Type": [
"application/xml"
],
"content-length": [
"29089"
]
},
"body": {
"type": "XML",
"xml": "string-value",
"contentType": "application/xml"
}
}
}
]
Related
I'd like to add JSON as the default to this swagger endpoint for the body of the POST request. I can not for the life of me figure out what this format is supposed to be to add a very large JSON object as the default for a POST endpoint. See example swagger spec below
{
"consumes": [
"application/x-www-form-urlencoded"
],
"definitions": {},
"info": {
"title": "swagger help",
"version": "1.0"
},
"paths": {
"/endpoint_name": {
"post": {
"consumes": [
"application/json"
],
"parameters": [
{
"default": {
"application/json": [{"test": "value"}]
},
"description": "JSON of a list of values",
"in": "body",
"name": "body",
"required": true,
"type": "object"
}
],
"produces": [
"application/json"
],
"security": [
{
"APIKeyHeader": [
"Authorization"
]
}
],
}
},
"produces": [
"application/json"
],
"securityDefinitions": {
"APIKeyHeader": {
"description": "description here",
"in": "header",
"name": "Authorization",
"type": "apiKey"
}
},
"swagger": "2.0"
}
In OpenAPI 2.0, body parameters use the schema keyword. That's where you specify the type, default, example, and other type-related details.
"parameters": [
{
"description": "JSON of a list of values",
"in": "body",
"name": "body",
"required": true,
"schema": {
"type": "object",
"default": {"test": "value"}
}
}
],
I am trying to translate a file ifc to svf. I'm making the upload in multi parts and seems to be correct.
This is the code Im using to translate
public async convertFileToSvfFormat(forgeApiAccessToken: string, urn: string): Promise<any> {
const forgeFileConversionResponse = await firstValueFrom(
this.forgeHttpService.post(
`modelderivative/v2/designdata/job`,
JSON.stringify({
input: {
urn,
},
output: {
formats: [
{
type: this.DEFAULT_FORGE_FORMAT_TYPE, // 'svf'
views: this.DEFAULT_FORGE_FORMAT_VIEWS, // ["2d", "3d"]
},
],
},
}),
{
headers: {
"Authorization": `Bearer ${forgeApiAccessToken}`,
"Content-Type": "application/json",
},
},
),
)
return forgeFileConversionResponse
}
But the manifest endpoint after a while throws this:
{
"urn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bnY5a2cyZnB5bTFsdDQ5MDkxdzdobXVsbzlha3RldXdfdHV0b3JpYWxfYnVja2V0L2MyMWE2MzcwZTMwNzJmM2IwZTA3OWE5MzRjYWM4YTZlLmlmYw",
"derivatives": [
{
"hasThumbnail": "false",
"name": "c21a6370e3072f3b0e079a934cac8a6e.ifc",
"progress": "complete",
"messages": [
{
"type": "error",
"message": "Unrecoverable exit code from extractor: -1073741829",
"code": "TranslationWorker-InternalFailure"
}
],
"outputType": "svf",
"status": "failed"
}
],
"hasThumbnail": "false",
"progress": "complete",
"type": "manifest",
"region": "US",
"version": "1.0",
"status": "failed"
}
Am I missing something? How can I know which is the error?
Thanks!
-edit
Here is the method in which Im uploading the files.
public async uploadFileToForgeBucket(forgeApiAccessToken: string, file: Express.Multer.File): Promise<void> {
// When de-hardcoding the Forge acocunt to assign accounts to each user, de-hardcode this value here
const bucketKey = this.getBucketKey(this.hardcodedForgeClientId)
const path = join(__dirname, "../../../../upload/") + file.filename
const parts = Math.floor(this.calculateFileChuncks(path))
const signedUrls = await this.getS3SignedUrl(forgeApiAccessToken, file.filename, parts)
parts > 1 && splitFileInChunks(path, parts)
console.log(`Number of parts: ${parts}`)
const timerId = setTimeout(async () => {
const fileName = parts > 1 ? `${file.filename}.sf-part${parts}` : file.filename
const exists = existsSync(`./upload/${fileName}`)
console.log(exists && "Last chunk exists and read...")
if (exists) {
console.log("Starting upload...")
for (let i = 0; i < signedUrls.urls.length; i++) {
const currentUrl = signedUrls.urls[i]
let part: string
if (parts > 9) {
part = (i + 1).toString().length === 1 ? `0${i + 1}` : (i + 1).toString()
} else {
part = (i + 1).toString()
}
const fileName = parts > 1 ? path + `.sf-part${part}` : path
const stream = readFileSync(fileName)
await firstValueFrom(
this.forgeHttpService.put(
currentUrl,
{ data: stream },
{
headers: {
"Content-Type": "application/octet-stream",
"Content-Length": stream.length,
// "Content-Range": `bytes 0-${stream.length}`,
"Content-Disposition": `${file.filename}.sf-part${part}`,
},
},
),
)
const percentage = ((i + 1) / parts) * 100
console.log(`Uploading file... ${percentage.toFixed(2)}%`)
}
console.log("Upload complete. Processing...")
console.log("Re-unifying file:", `${file.filename}`)
const result = await firstValueFrom(
this.forgeHttpService.post(
`https://developer.api.autodesk.com/oss/v2/buckets/${bucketKey}/objects/${file.filename}/signeds3upload`,
{
uploadKey: signedUrls.uploadKey,
},
{
headers: {
"Authorization": `Bearer ${forgeApiAccessToken}`,
"Content-Type": "application/json",
},
},
),
)
clearInterval(timerId)
console.log(result.data)
const toBase64 = stringToBase64(result.data.objectId)
console.log(toBase64)
const translation = await this.convertFileToSvfFormat(forgeApiAccessToken, toBase64)
console.log(translation)
// console.log(translation, "trans")
}
}, 2000)
The result for this is:
data: {
result: 'success',
urn: 'dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6eG02ZjIxbWUxMHNxbTc4NmlhY3c2cTV6bjUxeWdpZmhfdHV0b3JpYWxfYnVja2V0L3JhY19iYXNpY19zYW1wbGVfcHJvamVjdF92My5pZmM',
acceptedJobs: { output: [Object] }
}
After that I call the translation method. Which ends up failing with the error code I copied before.
What is your IFC schema version, IFC2x3 or IFC4?
For large IFC files and IFC4, I would advise you to use the v3 IFC conversion method. So here is the modification to your code. You can find the comparison table here: https://forge.autodesk.com/blog/faq-and-tips-ifc-translation-model-derivative-api
public async convertFileToSvfFormat(forgeApiAccessToken: string, urn: string): Promise<any> {
const forgeFileConversionResponse = await firstValueFrom(
this.forgeHttpService.post(
`modelderivative/v2/designdata/job`,
JSON.stringify({
input: {
urn,
},
output: {
formats: [
{
type: this.DEFAULT_FORGE_FORMAT_TYPE, // 'svf'
views: this.DEFAULT_FORGE_FORMAT_VIEWS, // ["3d"],
advanced: {
conversionMethod: 'v3'
}
},
],
},
}),
{
headers: {
"Authorization": `Bearer ${forgeApiAccessToken}`,
"Content-Type": "application/json",
"x-ads-force": true,
},
},
),
)
return forgeFileConversionResponse
}
Example manifest of using v3. The IFC Loader should be 3.
{
"urn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bXlidWNrZXQvcmFjX2Jhc2ljX3NhbXBsZV9wcm9qZWN0X3YzLmlmYw",
"derivatives": [
{
"hasThumbnail": "true",
"children": [
{
"guid": "d16f9899-ea0f-b40e-73fa-876f51b1352a",
"type": "geometry",
"role": "3d",
"name": "rac_basic_sample_project_v3.ifc",
"status": "success",
"viewableID": "rac_basic_sample_project_v3.ifc",
"hasThumbnail": "true",
"progress": "complete",
"useAsDefault": true,
"children": [
{
"guid": "72890b2b-0c4e-4e60-a168-3764b2c9922a",
"type": "view",
"role": "3d",
"name": "Default",
"status": "success",
"hasThumbnail": "true",
"camera": [
-11528.884765625,
-183404.859375,
5052.05517578125,
-11528.884765625,
-29944.34375,
5052.05517578125,
0,
-2.220446049250313e-16,
1,
1,
0.785398006439209,
1,
0
],
"useAsDefault": true,
"children": [
{
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bXlidWNrZXQvcmFjX2Jhc2ljX3NhbXBsZV9wcm9qZWN0X3YzLmlmYw/output/0/0_100.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "92474384-5af9-478e-b98a-be02e5005eab",
"type": "resource",
"resolution": [
100,
100
]
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bXlidWNrZXQvcmFjX2Jhc2ljX3NhbXBsZV9wcm9qZWN0X3YzLmlmYw/output/0/0_200.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "5567e9a6-2de2-46a3-a818-06cf1a8b916c",
"type": "resource",
"resolution": [
200,
200
]
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bXlidWNrZXQvcmFjX2Jhc2ljX3NhbXBsZV9wcm9qZWN0X3YzLmlmYw/output/0/0_400.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "02792503-61de-4880-b5bd-ffe17f06c9f8",
"type": "resource",
"resolution": [
400,
400
]
}
]
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bXlidWNrZXQvcmFjX2Jhc2ljX3NhbXBsZV9wcm9qZWN0X3YzLmlmYw/output/0/0.svf",
"role": "graphics",
"mime": "application/autodesk-svf",
"guid": "a65292fb-4676-47a2-a632-69b3bd01af30",
"type": "resource"
}
]
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bXlidWNrZXQvcmFjX2Jhc2ljX3NhbXBsZV9wcm9qZWN0X3YzLmlmYw/output/0/AECModelData.json",
"role": "Autodesk.AEC.ModelData",
"mime": "application/json",
"guid": "b13160e3-df69-4e43-a0e9-fd7c0b2e8d3a",
"type": "resource",
"status": "success"
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bXlidWNrZXQvcmFjX2Jhc2ljX3NhbXBsZV9wcm9qZWN0X3YzLmlmYw/output/0/properties.db",
"role": "Autodesk.CloudPlatform.PropertyDatabase",
"mime": "application/autodesk-db",
"guid": "06aac8bb-14c7-4775-9d3d-059a26b620ed",
"type": "resource",
"status": "success"
}
],
"name": "rac_basic_sample_project_v3.ifc",
"progress": "complete",
"outputType": "svf",
"properties": {
"Document Information": {
"Navisworks File Creator": "LcNwcLoaderPlugin:lcldifc",
"IFC Application Name": "Autodesk Revit 2022 (ENU)",
"IFC Application Version": "2022",
"IFC Organization": "Autodesk",
"IFC Schema": "IFC2X3",
"IFC Loader": "3"
}
},
"status": "success"
}
],
"hasThumbnail": "true",
"progress": "complete",
"type": "manifest",
"region": "US",
"version": "1.0",
"status": "success"
}
After some days trying I found the problem. I leave it here in case someone else has the same error and after trying all the things above couldn't solve it.
Im my case was simple as creating a new bucket. After doing so worked. Maybe the one with which I was trying was expired or something I don't know.
I have been trying desperately for 5 days to create an elasticsearch watcher alert that sends a notification on an incoming webhook teams. However, the answer I receive is "Bad payload received by generic incoming webhook". I do not understand why it does not work.
{
"trigger": {
"schedule": {
"interval": "2m"
}
},
"input": {
"simple": {
"summary": "Test Nom",
"text": "test"
}
},
"condition": {
"always": {}
},
"actions": {
"MS_TEAMS_PORT443": {
"webhook": {
"scheme": "https",
"host": "outlook.office.com",
"port": 443,
"method": "post",
"path": "/webhook/XYZ",
"params": {},
"headers": {
"content-type": "application/json"
},
"body": "{{#toJson}}ctx.payload.summary{{/toJson}}"
}
}
}
}
And this is the response when I launch it:
{
"watch_id": "_inlined_",
"node": "QUApyNq4S5GyhHF-CuNjfg",
"state": "executed",
"status": {
"state": {
"active": true,
"timestamp": "2019-10-21T08:40:39.802Z"
},
"last_checked": "2019-10-21T08:40:39.802Z",
"last_met_condition": "2019-10-21T08:40:39.802Z",
"actions": {
"MS_TEAMS_PORT443": {
"ack": {
"timestamp": "2019-10-21T08:40:39.802Z",
"state": "awaits_successful_execution"
},
"last_execution": {
"timestamp": "2019-10-21T08:40:39.802Z",
"successful": false,
"reason": "received [400] status code"
}
}
},
"execution_state": "executed",
"version": -1
},
"trigger_event": {
"type": "manual",
"triggered_time": "2019-10-21T08:40:39.802Z",
"manual": {
"schedule": {
"scheduled_time": "2019-10-21T08:40:39.802Z"
}
}
},
"input": {
"simple": {
"summary": "Test Nom",
"text": "test"
}
},
"condition": {
"always": {}
},
"metadata": {
"name": "testJsonALaMano",
"xpack": {
"type": "json"
}
},
"result": {
"execution_time": "2019-10-21T08:40:39.802Z",
"execution_duration": 125,
"input": {
"type": "simple",
"status": "success",
"payload": {
"summary": "Test Nom",
"text": "test"
}
},
"condition": {
"type": "always",
"status": "success",
"met": true
},
"actions": [
{
"id": "MS_TEAMS_PORT443",
"type": "webhook",
"status": "failure",
"reason": "received [400] status code",
"webhook": {
"request": {
"host": "outlook.office.com",
"port": 443,
"scheme": "https",
"method": "post",
"path": "/webhook/XYZ",
"headers": {
"content-type": "application/json"
},
"body": "Test Nom"
},
"response": {
"status": 400,
"headers": {
"date": [
"Mon, 21 Oct 2019 08:40:38 GMT"
],
"content-length": [
"49"
],
"expires": [
"-1"
],
"x-beserver": [
"VI1PR07MB5053"
],
"x-aspnet-version": [
"4.0.30319"
],
"x-proxy-backendserverstatus": [
"400"
],
"x-cafeserver": [
"VE1PR03CA0023.EURPRD03.PROD.OUTLOOK.COM"
],
"x-calculatedbetarget": [
"VI1PR07MB5053.eurprd07.prod.outlook.com"
],
"request-id": [
"6d651f70-74b5-4010-a2a6-662666fa9985"
],
"pragma": [
"no-cache"
],
"x-msedge-ref": [
"Ref A: C6E8A3DCFF9541DD95D63FD71ACD695C Ref B: PAR02EDGE0513 Ref C: 2019-10-21T08:40:39Z"
],
"x-feserver": [
"VE1PR03CA0023"
],
"x-powered-by": [
"ASP.NET"
],
"x-backendhttpstatus": [
"400"
],
"content-type": [
"text/plain; charset=utf-8"
],
"cache-control": [
"no-cache"
]
},
"body": "Bad payload received by generic incoming webhook."
}
}
}
]
},
"messages": []
}
Wrong body statement. Need to send text in body. Change your body to be like this
"body": "{\"text\": \"{{ctx.payload.summary}}\"}"
source property is your friend here:
"body": {
"source": {
"text" : "Test Nom"
}
}
I'm trying to post to my Mockable API using Axios and React Native,
I'm quite inexperienced with Axios and Mockable and am not sure If I'm getting the response that I'm suppose to.
To explain:
In my app I've got a set of data (order data) which I'm trying to post to my mockable api.
So what I expect is
to add an order with the data from below to my API everytime I hit post.
What is happening
Everytime I hit post an order does not get added to my API.
How do I add objects to my Mockable API using Axios and React Native?
class BarPaymentScreen extends Component{
static navigationOptions = {
// header: null,
};
constructor(props){
super(props);
this.state ={
isLoading: false,
orderRestaurantId : 'empty',
orderValue: 'empty',
orderProducts: 'empty',
orderTotalPrice: 'empty',
}
}
handleSubmit = () => {
this.setState({
orderRestaurantId : this.props.restaurantId,
orderValue: this.state.value,
orderProducts: this.props.products,
orderTotalPrice: this.props.totalPrice,
})
axios({
method: 'post',
url: 'https://demo3381137.mockable.io/orders',
data: {
orders: {
orderId: '1',
restaurantId: this.state.orderRestaurantId,
orderKey: "AppOrderKey",
userId: "1",
paymentStatus: "approved",
preparing: "approved",
orderStatus: "approved",
paymentMethod: this.state.orderValue,
totalPrice: this.state.orderTotalPrice,
order: [
{
product : "bier",
qty : "5"
}
]
}
}
}).then(function (response) {
console.log('response',response);
})
.catch(function (error) {
console.log("error response",error);
});
console.log('submit');
}
Response Data
response Object {
"config": Object {
"adapter": [Function xhrAdapter],
"data": "{\"orders\":{\"orderId\":\"1\",\"restaurantId\":\"empty\",\"orderKey\":\"AppOrderKey\",\"userId\":\"1\",\"paymentStatus\":\"approved\",\"preparing\":\"approved\",\"orderStatus\":\"approved\",\"paymentMethod\":\"empty\",\"totalPrice\":\"empty\",\"order\":[{\"product\":\"bier\",\"qty\":\"5\"}]}}",
"headers": Object {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json;charset=utf-8",
},
"maxContentLength": -1,
"method": "post",
"timeout": 0,
"transformRequest": Object {
"0": [Function transformRequest],
},
"transformResponse": Object {
"0": [Function transformResponse],
},
"url": "https://demo3381137.mockable.io/orders",
"validateStatus": [Function validateStatus],
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
},
"data": Object {
"orders": Array [
Object {
"restaurantId": "1",
"order": Array [
Object {
"product": "bier",
"qty": "5",
},
Object {
"product": "wisky",
"qty": "5",
},
Object {
"product": "fanta",
"qty": "5",
},
],
"orderId": "1",
"orderKey": "F3SAR566T",
"orderStatus": "approved",
"paymentMethod": "approved",
"paymentStatus": "approved",
"preparing": "approved",
"totalPrice": 10,
"userId": "1",
},
],
},
"headers": Object {
"access-control-allow-origin": "*",
"cache-control": "public, max-age=0",
"content-length": "721",
"content-type": "application/json; charset=UTF-8",
"date": "Mon, 18 Mar 2019 20:45:23 GMT",
"server": "Google Frontend",
"x-cloud-trace-context": "9a52c3976772c84992f870c94d8316a2",
},
"request": XMLHttpRequest {
"DONE": 4,
"HEADERS_RECEIVED": 2,
"LOADING": 3,
"OPENED": 1,
"UNSENT": 0,
"_aborted": false,
"_cachedResponse": undefined,
"_hasError": false,
"_headers": Object {
"accept": "application/json, text/plain, */*",
"content-type": "application/json;charset=utf-8",
},
"_incrementalEvents": false,
"_lowerCaseResponseHeaders": Object {
"access-control-allow-origin": "*",
"cache-control": "public, max-age=0",
"content-length": "721",
"content-type": "application/json; charset=UTF-8",
"date": "Mon, 18 Mar 2019 20:45:23 GMT",
"server": "Google Frontend",
"x-cloud-trace-context": "9a52c3976772c84992f870c94d8316a2",
},
"_method": "POST",
"_requestId": null,
"_response": "{
\"orders\": [
{
\"orderId\": \"1\",
\"restaurantId\": \"1\",
\"orderKey\": \"F3SAR566T\",
\"userId\": \"1\",
\"paymentStatus\": \"approved\",
\"preparing\": \"approved\",
\"orderStatus\": \"approved\",
\"paymentMethod\": \"approved\",
\"totalPrice\": 10,
\"order\": [
{
\"product\" : \"bier\",
\"qty\" : \"5\"
},
{
\"product\" : \"wisky\",
\"qty\" : \"5\"
},
{
\"product\" : \"fanta\",
\"qty\" : \"5\"
}
]
}
]
}",
"_responseType": "",
"_sent": true,
"_subscriptions": Array [],
"_timedOut": false,
"_trackingName": "unknown",
"_url": "https://demo3381137.mockable.io/orders",
"readyState": 4,
"responseHeaders": Object {
"Cache-Control": "public, max-age=0",
"access-control-allow-origin": "*",
"content-length": "721",
"content-type": "application/json; charset=UTF-8",
"date": "Mon, 18 Mar 2019 20:45:23 GMT",
"server": "Google Frontend",
"x-cloud-trace-context": "9a52c3976772c84992f870c94d8316a2",
},
"responseURL": "https://demo3381137.mockable.io/orders",
"status": 200,
"timeout": 0,
"upload": XMLHttpRequestEventTarget {
Symbol(listeners): Object {},
},
"withCredentials": true,
Symbol(listeners): Object {
"error": Object {
"kind": 3,
"listener": [Function handleError],
"next": null,
},
"readystatechange": Object {
"kind": 3,
"listener": [Function handleLoad],
"next": null,
},
"timeout": Object {
"kind": 3,
"listener": [Function handleTimeout],
"next": null,
},
},
},
"status": 200,
"statusText": undefined,
}
Code worked, Mockable.io has a page which shows the response to my posts.
2 Questions:
1) I want to keep the json as is but change the Timestamp to human readable date like "2016-12-19T09:21:35Z"
{
"Action": "ALLOW",
"Timestamp": 1482139256.274,
"Request": {
"Country": "US",
"URI": "/version/moot/beta.json",
"Headers": [
{
"Name": "Host",
"Value": "static.tiza.com"
},
{
"Name": "User-Agent",
"Value": "Faraday v0.9.2"
},
{
"Name": "Accept-Encoding",
"Value": "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
},
{
"Name": "Accept",
"Value": "*/*"
},
{
"Name": "X-Newrelic-Id",
"Value": "Vgcs5gbFU123dFBWGwIdAVFdrXBwc="
},
{
"Name": "X-Newrelic-Transaction",
"Value": "PxQDQVlzZVUd3NKQcrEwWwU"
}
],
"ClientIP": "107.22.17.51",
"Method": "GET",
"HTTPVersion": "HTTP/1.1"
},
"Weight": 1
}
I know I can do it using 'todate' jq feature but I lose all other data
sh# cat temp.json | jq -r '.SampledRequests[].Timestamp | todate'
2016-12-19T09:21:44Z
--------- Updated --------
second question:
2)How do I take the content of .Headers[] out of the array under the "Request{}" level.
from:
{
"TimeWindow": {
"EndTime": 1482156660,
"StartTime": 1482156420
},
"SampledRequests": [
{
"Action": "ALLOW",
"Timestamp": 1482139256.274,
"Request": {
"Country": "US",
"URI": "/version/moot/beta.json",
"Headers": [
{
"Name": "Host",
"Value": "static.tiza.com"
},
{
"Name": "X-Newrelic-Transaction",
"Value": "PxQDQVlzZVUd3NKQcrEwWwU"
}
],
"ClientIP": "107.22.17.51",
"Method": "GET",
"HTTPVersion": "HTTP/1.1"
},
"Weight": 1
}
],
"PopulationSize": 89
}
To:
{
"TimeWindow.EndTime": 1482156660,
"TimeWindow.StartTime": 1482156420,
"Action": "ALLOW",
"Timestamp": 1482139256.274,
"Request.Country": "US",
"Request.URI": "/version/moot/beta.json",
"Headers.Host": "static.tiza.com",
"Headers.X-Newrelic-Transaction": "PxQDQVlzZVUd3NKQcrEwWwU",
"ClientIP": "107.22.17.51",
"Method": "GET",
"HTTPVersion": "HTTP/1.1",
"Weight": 1,
"PopulationSize": 89
}
Thanks a lot,
Moshe
1) Use |= rather than just |
2) One way to transform the fragment:
{
"Headers": [
{
"Name": "Host",
"Value": "static.tiza.com"
},
{
"Name": "User-Agent",
"Value": "Faraday v0.9.2"
}
]
}
as required would be using the filter:
.Headers[] | { ("Headers." + .Name): .Value }
In your case, you could therefore use the following filter for (2):
.SampledRequests[].Request.Headers[] |=
{ ("Headers." + .Name): .Value }
I'll leave it to you to put all the pieces together :-)