match results of SQL Query with JSON result from Invoke-RestMethod - json

I have two JSON files that i need to match for similar data and return only the matching data. 1 file is a result of a SQL query and another is a result of a Invoke-RestMethod Get request
i have tried to store the different json data into arrays but i am able to drill down properly into the JSON objects
[Here are the two JSON Files]
SQL Query results JSON file:
[
{
"OnCallTeamName": "1 Park Ave Support Corporate Desktop Support Teams",
"ContactPrimaryLoginID": "chungn03",
"ContactSecondaryLoginID": "chungn03",
"FirstEscalationLoginID": "giakog01",
"SecondaryEscalationLoginID": null
},
{
"OnCallTeamName": "14 Wall Street Support Corporate Desktop Support Teams",
"ContactPrimaryLoginID": "gendua01",
"ContactSecondaryLoginID": "gendua01",
"FirstEscalationLoginID": "giakog01",
"SecondaryEscalationLoginID": null
},
"OnCallTeamName": "WUH Technology Managers",
"ContactPrimaryLoginID": "corond01",
"ContactSecondaryLoginID": "carela02",
"FirstEscalationLoginID": "corond01",
"SecondaryEscalationLoginID": null
},
{
"OnCallTeamName": "Xper",
"ContactPrimaryLoginID": "greenj23",
"ContactSecondaryLoginID": "greenj23",
"FirstEscalationLoginID": "daniet02",
"SecondaryEscalationLoginID": null
}
]
REST call JSON file:
[
{
"group_name": "Outage Management Team",
"group_onlinemembers": [
{
"user_username": "moraly01",
"user_firstname": "Yvette",
"user_lastname": "Morales",
"user_id": "58"
}
]
},
{
"group_name": "Ivanti HEAT",
"group_onlinemembers": [
{
"user_username": "vasquj01",
"user_firstname": "Jose",
"user_lastname": "Vasquez",
"user_id": "148"
},
{
"user_username": "moraly01",
"user_firstname": "Yvette",
"user_lastname": "Morales",
"user_id": "58"
}
]
},
{
"group_name": "Telecommunications",
"group_onlinemembers": [
{
"user_username": "moraly01",
"user_firstname": "Yvette",
"user_lastname": "Morales",
"user_id": "58"
},
{
"user_username": "fernad04",
"user_firstname": "David",
"user_lastname": "Fernandez",
"user_id": "150"
},
{
"user_username": "efg213",
"user_firstname": "Edwin",
"user_lastname": "Guerrero",
"user_id": "76"
},
{
"user_username": "reyesl07",
"user_firstname": "Louis",
"user_lastname": "Reyes",
"user_id": "75"
}
]
},
{
"group_name": "NYU Data Center Operations",
"group_onlinemembers": [
]
}
]
I need to know how to use powershell to loop through these JSON Files and only pull out the matching items

Related

How to get the index of the object from json file in python

I have a json file with this structure
"user_data": {
"0": {
"user_name": "LinkedIn",
"type": "textfile"
"id": "543211",
"all_tickets": [
"56788",
"43224",
"56788"
]
};
"1": {
"user_name": "stackoverflow",
"type": "textfile"
"id": "123456",
"all_tickets": [
"98134",
"76372",
"44522"
]
}
}
}
Whenever user inputs the same data, I want to check against the existing one in the json file and if it matches, I want to return the index. How can I get it?
For example, if a user inputs the same keys and values of :
"user_name": "LinkedIn",
"type": "textfile"
"id": "543211",
"all_tickets": [
"56788",
"43224",
"56788"
]
The output should be 0(since that is the index)

How to save data in Json format in React-admin v3?

I created JsonInput, which sends a json object to the input SimpleForm, however, a modified version of it gets into the Data Provider.
that's what is sent to the input:
json: {
"FunctionalGroup": [
{
"uaIDref": [
"2104"
],
"_Name": "Текущие параметры",
"_ID": "33"
},
{
"uaIDref": [
"2100"
],
"_Name": "Текущие параметры пониженной точности",
"_ID": "34"
},
],
"_Name": "Прибор 1",
"_ID": "32"
}
that's what came to the server:
json: {
"FunctionalGroup": [
{
"uaIDref": [
"2104"
],
"_Name": "Текущие параметры",
"_ID": "33"
},
{
"uaIDref": [
"2100"
],
"_Name": "Текущие параметры пониженной точности",
"_ID": "34"
}
],
"FunctionalGroupIds": "",
"_Name": "Прибор 1",
"_ID": "32"
},
after a response from the server with this object, this is what came in the field:
json: {
FunctionalGroup: [
{
uaIDref: [
'2104'
]
},
{
uaIDref: [
'2100'
]
}
],
FunctionalGroupIds: ''
}
what kind of magic is this?
I did some tests. When I converted the object to a string, the correct json was sent to the server, however, in the field after the server responded, the modified object was displayed again.
I found out that the conversion is related to redux.js, but what exactly happens is not understood.
Please give any comments on this.
How can I make save json?

GraphQL Query returns null objects both in GraphiQL and App from JSON data source

I'm trying to get my mocked JSON data via GraphQL in Gatsby. The response shows the correct data, but also two null objects as well. Why is it happening?
I'm using the gatsby-transformer.json plugin to query my data and gatsby-source-filesystem to point the transformer to my json files.
categories.json
the mock file I'm trying to get to work :)
{
"categories": [
{
"title": "DEZERTY",
"path": "/dezerty",
"categoryItems": [
{
"categoryName": "CUKRIKY",
"image": "../../../../static/img/dessertcategories/cukriky.jpg"
},
{
"categoryName": "NAHODNE",
"image": "../../../../static/img/dessertcategories/nahodne.jpg"
},
]
},
{
"title": "CANDY BAR",
"path": "/candy-bar",
"categoryItems": [
{
"categoryName": "CHEESECAKY",
"image": "../../../../static/img/dessertcategories/cheesecaky.jpg"
},
{
"categoryName": "BEZLEPKOVÉ TORTY",
"image": "../../../../static/img/dessertcategories/bezlepkove-torty.jpg"
},
]
}
]
}
GraphQL query in GraphiQL
query Collections {
allMockJson {
edges {
node {
categories {
categoryItems {
categoryName
image
}
title
path
}
}
}
}
}
And the response GraphiQL gives me
{
"data": {
"allMockJson": {
"edges": [
{
"node": {
"categories": null
}
},
{
"node": {
"categories": null
}
},
{
"node": {
"categories": [
{
"categoryItems": [
{
"categoryName": "CHEESECAKY",
"image": "../../../../static/img/dessertcategories/cheesecaky.jpg"
},
{
"categoryName": "BEZLEPKOVÉ TORTY",
"image": "../../../../static/img/dessertcategories/bezlepkove-torty.jpg"
}
],
"title": "DEZERTY",
"path": "/dezerty"
},
{
"categoryItems": [
{
"categoryName": "CUKRIKY",
"image": "../../../../static/img/dessertcategories/CUKRIKY.jpg"
},
{
"categoryName": "NAHODNE",
"image": "../../../../static/img/dessertcategories/NAHODNE.jpg"
}
],
"title": "CANDY BAR",
"path": "/candy-bar"
}
]
}
}
]
}
}
}
I expected only to get the DEZERTY and CANDY BAR sections. Why are there null categories and how do I fix it?
Thanks in advance
Your JSON contains syntax errors in the objects DEZERTY and CANDY BAR. It silently fails without telling you. Try this json linter.
Error: Parse error on line 12: },
Error: Parse error on line 25: },
Try again. Your query should work now.
You should look into an IDE that highlights these types of errors and saves you time and frustration.

Sending the JSON response as array or normal object

I am implementing a restful service where I am getting the pdf names and their ids from the database in the JSON fromat. Which one of the both the convenient JSON resful service response?
First Option:
{
"results": {
"documentNames": [
"test.pdf",
"ireport-ultimate-guide.pdf",
"sending report.pdf",
"Motor Hour.pdf"
],
"documentds": [
21116,
21117,
21118,
21119
]
}
}
Second Option:
{
"results": {
"21116": "test.pdf",
"21117": "ireport-ultimate-guide.pdf",
"21118": "sending report.pdf",
"21119": "Motor Hour.pdf"
}
}
I would use this "third option": The result is a list of object.
{
"result": [{
"id": "21116",
"filename": "test.pdf"
},
{
"id": "21117",
"filename": "ireport-ultimate-guide.pdf"
},
{
"id": "21118",
"filename": "sending report.pdf"
},
{
"id": "21119",
"filename": "Motor Hour.pdf"
}
]
}
because it better models the object structure.
I would create an entity for each document that contains both name and I'd.
[
{"name": "doc_1", "id": 123},
{"name": "doc_2", "id": 456}
]

creating JSON object without using a list

I want to be able to create a JSON object so that I can access it like this.
education.schools.UNCC.graduation
Currently, my JSON is like this:
var education = {
"schools": [
"UNCC": {
"graduation": 2015,
"city": "Charlotte, NC",
"major": ["CS", "Spanish"]
},
"UNC-CH": {
"graduation": 2012,
"city": "Chapel Hill, NC"
"major": ["Sociology", "Film"]
}
],
"online": {
"website": "Udacity",
"courses": ["python", "java", "data science"]
}
};
When I go to Lint my JSON, I get an error message.
I know I can reformat my object to access it like this (below), but I don't want to do it this way. I want to be able to call the school name, and not use an index number.
education.schools[1].graduation
Objects have named keys. Arrays are a list of members.
Replace the value of "schools" with an object. Change [] to {}.
This is your JSON corrected.
Your JSON is invalid.
{
"schools": [
{
"UNCC": {
"graduation": "2015",
"city": [
"CS",
"Spanish"
],
"major": [
"CS",
"Spanish"
]
}
},
{
"UNC-CH": {
"graduation": "2012",
"city": [
"Chapel Hill",
"NC"
],
"major": [
"Sociology",
"Film"
]
}
}
],
"online": {
"website": "Udacity",
"courses": [
"python",
"java",
"data science"
]
}
}
Explanation:
"city": "Chapel Hill, NC" -> this is a array with 2 values "Chapel Hill" and "HC", like you do with major and courses.
The Schools array, you need to use this sintaxe to construct a array [{
http://adobe.github.io/Spry/samples/data_region/JSONDataSetSample.html