I need assistance in building my own json schema - json

How do I build my own json schema to validate the json coming back from an api is the same structure? I have this sample JSON
{
"httpStatus": 200,
"httpStatusMessage": "success",
"timestamp": "2020-11-11T19:32:45",
"response": {
"header": {
"SchoolId": 10006,
"SchoolName": "Naples"
},
"body": {
"dataProviders": [
{
"dataProviderId": 14,
"students": [
{
"studentId": 1000611000,
"driverGrade": "Junior",
"firstName": "Authur",
"lastName": "Boccuto"
},
{
"studentId": 1000611001,
"studentGrade": "Senior",
"firstName": "Antwan",
"lastName": "Carter"
}
]
}
]
}
}
}
At times it can come in with a different structure and I need to build my own json schema to validate that it's the same before manipulating the json data. How do I build my own schema to make sure that it has a valid structure?

Related

graphql, nesjs and prisma api response solution need

i use nestjs, graphQL and prisma module to create my endpoint and web service ;
i am looking for way to create custom response in graphQL my endpoint is simple
select books from database my response is
{
"data": {
"books": [
{
"id": "5b5c02beab8dc1182b2e0a03",
"name": "dasta"
},
{
"id": "5b5c02c0ab8dc1182b2e0a04",
"name": "dasta"
}
]
}
}
but in need something like this
{
"result": "success",
"msg" : "list ...",
"data": [
{
"id": "5b5c02beab8dc1182b2e0a03",
"name": "dasta"
},
{
"id": "5b5c02c0ab8dc1182b2e0a04",
"name": "dasta"
}
]
}

JSONAARAY Parsing when dynamic key of object

I am trying to parse json that has dynamic key values. Here is my json format.
Works with flutter
{
"status": "success",
"data": [
{
"accepted": [
{
"id": 15,
"emp_id": 3,
}
]
},
{
"negotiate": [
{
"id": 15,
"emp_id": 3,
}
]
},
]
}
here accepted and negotiate is dynamic key.

how to remove json element using json parse in logic app?

Input json -
{
"data": {
"Testresults": [
{
"mydata": {
"id": "111",
"uri": "url",
"type": "demo"
},
"name": "",
"address": "",
in side Parse Json schema added as below -
{
"properties": {
"data": {
"properties": {
"Testresults": {
"items": {
"properties": {
"name": {
"type": "string"
},
"address": {
"type": "string"
}
I have removed mydata from Parse Json schema still in the output getting same input json.
I want to remove mydata element from input json and pass it further , what should be done for that in parseJson?
expected output after Parse Json
{
"data": {
"Testresults": [
{
"name": "",
"address": "",
For your requirement, I post my steps below for your reference.
In my logic app, I use the json below as the input data:
{
"data": {
"Testresults": [
{
"mydata": {
"id": "111",
"uri": "url",
"type": "demo1"
},
"name": "Michael",
"address": "abc"
},
{
"mydata": {
"id": "222",
"uri": "url",
"type": "demo2"
},
"name": "Daniel",
"address": "def"
}
]
}
}
First I create a variable to store it.
Then, parse json.
After that, we can use liquid. We need to create an integration account and link to the logic app, then upload the liquid map shown as below:
{
"data": {
"Testresults": [
{% for testresult in content.data.Testresults %}
{
"name": "{{testresult.name}}",
"address": "{{testresult.address}}"
},
{% endfor %}
]
}
}
Now, we can use "Transform JSON to JSON" action to do convert it.
Run the logic app, I get the result we expect.(without "mydata")
Hope it would be helpful to your requirement~

Using a template variable that contains a JSON object with Postman Collection Runner

I am attempting to use the Postman collection runner to post several objects to an API from a JSON file structured something like this:
[
{
"id": "170",
"body": {
"name": "prod1",
"category": "category1"
},
"anotherProperty": "xyz"
},
{
"id": "171",
"body": {
"name": "prod3",
"category": "category1"
},
"anotherProperty": "dfg"
},
{
"id": "172",
"body": {
"name": "prod3",
"category": "category1"
},
"anotherProperty": "abc"
}
]
My problem seems to be with the body since it is an object:
Here is what I have in the Body > raw application/json of the request that my collection is using:
{
"$id": "{{id}}",
"body": {{body}},
"anotherProperty": "{{anotherProperty}}"
}
When viewing what it is plugging in it looks like:
{
"id": "170",
"body": {[object Object]}, // instead of the actual object
"anotherProperty": "xyz"
}
I needed to add the following to the Pre-request script:
let properties = pm.iterationData.get('properties');
pm.variables.set('properties', JSON.stringify(properties));
let body = pm.iterationData.get('body');
pm.variables.set('body', JSON.stringify(body));
And the raw JSON is plugged in with no problem!

DRF: Serializing data from external network request

I'm using Django Rest Framework and making external network request which data isn't needed in models but pure serializers.
I make an external request to get some data from a server which returns JSON. Here is a quick snipped of it.
{
"request": [
{
"packages": {
"gold": [
{
"name": "Gold Package 1",
"value": "Gold1"
},
{
"name": "Gold Package 2",
"value": "Gold2"
}
],
"bronze": [
{
"name": "Bronze package 1",
"value": "Bronze1"
},
{
"name": "Bronze Package 2",
"value": "Bronze2"
}
]
}
]
}
After getting this request, I want to return data within this format.
How can this be achieved?
"response": [{
"details": {
"legacy_packages": [{
"name": "Gold Package 1",
},
{
"name": "Gold Package 2",
}
]
}
},
Do you really need serializer for this? Looks like plain code will be ok. Assuming request variable to be the first dictionary:
response = {
'response': [{
"details": {
"legacy_packages": [
{
"name": package['name'],
}
for package in request['request'][0]['packages']['gold']
]
}
}]
}
Introduce intermediate variables if needed for clarity and cleaner code.