deserializing JSon with different Parent node names - json

I'm trying to deserializing a json response from Gitblit using c# and i'm getting it back in the following format
{
"https://localhost/git/libraries/xmlapache.git": {
"name": "libraries/xmlapache.git",
"description": "apache xmlrpc client and server",
"owner": "admin",
"lastChange": "2010-01-28T22:12:06Z",
"hasCommits": true,
"showRemoteBranches": false,
"useTickets": false,
"useDocs": false,
"accessRestriction": "VIEW",
"isFrozen": false,
"showReadme": false,
"federationStrategy": "FEDERATE_THIS",
"federationSets": [
"libraries"
],
"isFederated": false,
"skipSizeCalculation": false,
"skipSummaryMetrics": false,
"size": "102 KB"
},
"https://localhost/git/libraries/smack.git": {
"name": "libraries/smack.git",
"description": "smack xmpp client",
"owner": "admin",
"lastChange": "2009-01-28T18:38:14Z",
"hasCommits": true,
"showRemoteBranches": false,
"useTickets": false,
"useDocs": false,
"accessRestriction": "VIEW",
"isFrozen": false,
"showReadme": false,
"federationStrategy": "FEDERATE_THIS",
"federationSets": [],
"isFederated": false,
"skipSizeCalculation": false,
"skipSummaryMetrics": false,
"size": "4.8 MB"
}
}
and i'm having trouble creating the DataContract due to the parent nodes being named from the pull url and could be anything rather than a standardised name. i only need to deserialize "name":,"description":, "owner":, "lastChange" from underneath them.
so is there a way i can deserialize each dataset while ignoring the parent node all together?

Related

JSON generator problem index doesn't implement correctly

Hi I've got a problem who drive me crazy. I want to generate a JSON file of 9999 elements, I'm currently using this web https://json-generator.com/.
I use 'index' to implements number on my JSON file the problem is that one of the index doesn't work and doesn't implement correctly and i dont how why. There is some code to understand my problem.
There is the original code to generate the JSON file :
[
'{{repeat(9999)}}',
{
file_path: 'C:/Users/Maxime Guenneteau/Desktop/Open Sea Collection/Into the depth of infinity/Images/frctl_{{index(0,9999)}}.png',
nft_name : 'Fractal #{{index(0,9999)}}',
external_link: "",
description: 'Mandelbrot Fractal N°{{index(0,9999)}}',
collection: 'Into The Depth Of Infinity',
properties: '',
levels: [{'name': 'Number', 'from': '{{index(0,9999)}}', 'to': 9999 }],
unlockable_content: false,
explicit_and_sensitive_content: false,
supply: 1,
blockchain: 'Ethereum'}]
The index of the levels attributes doesn't implement correctly:
{
"file_path": "C:/Users/Maxime Guenneteau/Desktop/Open Sea Collection/Into the depth of infinity/Images/frctl_2480.png",
"nft_name": "Fractal #2480",
"external_link": "",
"description": "Mandelbrot Fractal N°2480",
"collection": "Into The Depth Of Infinity",
"properties": "",
"levels": [
{
"name": "Number",
"from": 0,
"to": 9999
}],
"unlockable_content": false,
"explicit_and_sensitive_content": false,
"supply": 1,
"blockchain": "Ethereum"},{
"file_path": "C:/Users/Maxime Guenneteau/Desktop/Open Sea Collection/Into the depth of infinity/Images/frctl_2481.png",
"nft_name": "Fractal #2481",
"external_link": "",
"description": "Mandelbrot Fractal N°2481",
"collection": "Into The Depth Of Infinity",
"properties": "",
"levels": [
{
"name": "Number",
"from": 0,
"to": 9999
}
],
"unlockable_content": false,
"explicit_and_sensitive_content": false,
"supply": 1,
"blockchain": "Ethereum"},
As we can see the Number from 0 to 9999 should implement like the other index but don't.
Thank you for your help

How to configure everything into one or multiple configure files

I haven't used this since 2 years ago. I'm trying to figure out how to put everything into one json or it has to be mulitple jsons.
Using v11.9.46. The documentation is not clear as it references things that are for one version or another.
I'm moving items from ADOorg1 to ADOorg2. In this order I was going to setup the json
Areas and Iterations
Team setup
Shared Queries
Work Items (using a query to find select area)
This is what I had so far as I tried to figure out how to put it into one:
{
"ChangeSetMappingFile": null,
// "Endpoints": {
// "TfsTeamSettingsEndpoints": [
// {
// "Name": "TeamSettingsSource",
// "AccessToken": "",
// "Query": {
// "Query": "SELECT [System.Id], [System.Tags] FROM WorkItems WHERE [System.TeamProject] = #TeamProject AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan') ORDER BY [System.ChangedDate] desc"
// },
// "Organisation": "https://dev.azure.com/test1/",
// "Project": "test1",
// "ReflectedWorkItemIdField": "ReflectedWorkItemId",
// "AuthenticationMode": "AccessToken",
// "AllowCrossProjectLinking": false,
// "LanguageMaps": {
// "AreaPath": "Area",
// "IterationPath": "Iteration"
// }
// },
// {
// "Name": "TeamSettingsTarget",
// "AccessToken": "",
// "Query": {
// "Query": "SELECT [System.Id], [System.Tags] FROM WorkItems WHERE [System.TeamProject] = #TeamProject AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan') ORDER BY [System.ChangedDate] desc"
// },
// "Organisation": "https://dev.azure.com/test2/",
// "Project": "test2",
// "ReflectedWorkItemIdField": "ReflectedWorkItemId",
// "AuthenticationMode": "AccessToken",
// "AllowCrossProjectLinking": false,
// "LanguageMaps": {
// "AreaPath": "Area",
// "IterationPath": "Iteration"
// }
// }
// ]
// },
"Source": {
"$type": "TfsTeamProjectConfig",
"Collection": "https://dev.azure.com/test1/",
"Project": "test1",
"ReflectedWorkItemIDFieldName": "ReflectedWorkItemId",
"AllowCrossProjectLinking": false,
"AuthenticationMode": "Prompt",
"PersonalAccessToken": "",
"LanguageMaps": {
"AreaPath": "Area",
"IterationPath": "Iteration"
}
},
"Target": {
"$type": "TfsTeamProjectConfig",
"Collection": "https://dev.azure.com/test2/",
"Project": "Test2",
"ReflectedWorkItemIDFieldName": "ReflectedWorkItemId",
"AllowCrossProjectLinking": false,
"AuthenticationMode": "Prompt",
"PersonalAccessToken": "",
"LanguageMaps": {
"AreaPath": "Area",
"IterationPath": "Iteration"
}
},
"Endpoints": {
"InMemoryWorkItemEndpoints": [
{
"Name": "Source",
"EndpointEnrichers": null
},
{
"Name": "Target",
"EndpointEnrichers": null
}
]
},
"GitRepoMapping": null,
"LogLevel": "Information",
"Processors": [
{
"$type": "TfsAreaAndIterationProcessorOptions",
"Enabled": true,
"PrefixProjectToNodes": false,
"NodeBasePaths": null,
"ProcessorEnrichers": null,
"SourceName": "Source",
"TargetName": "Target"
},
{
"$type": "TfsTeamSettingsProcessorOptions",
"Enabled": false,
"MigrateTeamSettings": true,
"UpdateTeamSettings": true,
"PrefixProjectToNodes": false,
"Teams": null,
"ProcessorEnrichers": null,
"SourceName": "Source",
"TargetName": "Target"
},
{
"$type": "WorkItemMigrationConfig",
"Enabled": false,
"ReplayRevisions": true,
"PrefixProjectToNodes": false,
"UpdateCreatedDate": true,
"UpdateCreatedBy": true,
"BuildFieldTable": false,
"AppendMigrationToolSignatureFooter": false,
"WIQLQueryBit": "AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')",
"WIQLOrderBit": "[System.ChangedDate] desc",
"LinkMigration": true,
"AttachmentMigration": true,
"AttachmentWorkingPath": "E:\\temp\\WorkItemAttachmentWorkingFolder\\",
"FixHtmlAttachmentLinks": false,
"SkipToFinalRevisedWorkItemType": true,
"WorkItemCreateRetryLimit": 5,
"FilterWorkItemsThatAlreadyExistInTarget": true,
"PauseAfterEachWorkItem": false,
"AttachmentMaxSize": 480000000,
"CollapseRevisions": false,
"LinkMigrationSaveEachAsAdded": false,
"GenerateMigrationComment": true,
"NodeBasePaths": [
"Product\\Area\\Path1",
"Product\\Area\\Path2"
],
"WorkItemIDs": null
}
],
"Version": "0.0",
"workaroundForQuerySOAPBugEnabled": false,
"WorkItemTypeDefinition": {
"sourceWorkItemTypeName": "targetWorkItemTypeName"
}
// "Endpoints": {
// "InMemoryWorkItemEndpoints": [
// {
// "Name": "Source",
// "EndpointEnrichers": null
// },
// {
// "Name": "Target",
// "EndpointEnrichers": null
// }
// ]
// }
}
If you use this Azure DevOps Migration Tools, it can migrate Work Items, TestPlans & Suits, Teams, Shared Queries, & Pipelines from one Organization to another. You could refer to Processors: TfsAreaAndIterationProcessor, TfsTeamSettingsProcessor, TfsSharedQueryProcessor and Work Item Tracking Processor to create corresponding configuration Json files one by one.

Json dynamic fields to struct issue [duplicate]

This question already has answers here:
Decoding generic JSON objects to one of many formats
(1 answer)
How to parse a complicated JSON with Go unmarshal?
(3 answers)
golang | unmarshalling arbitrary data
(2 answers)
How to parse JSON in golang without unmarshaling twice
(3 answers)
Is it possible to partially decode and update JSON? (go)
(2 answers)
Closed 10 months ago.
Every time I resolve one issue I get into another similar but different.
I need to convert into struts below JSON, but some parts are dynamic. and I am not very experienced with this conversions and I get very confused.
Below I have two fields that are different not static ( I was able with the help of this forum resolve a similar issue with one dynamic entry, but now I have two).
the fields I called them "This string changes" so is less confusing.
[null,null,"hub:zWXKROOM","presence_state",{"74ce1906-af89-48a9-aec7-501369509000":{"metas":[{"context":{"embed":false,"mobile":false},"permissions":{"close_hub":false,"embed_hub":false,"fly":true,"join_hub":true,"kick_users":false,"mute_users":false,"pin_objects":false,"spawn_and_move_media":true,"spawn_camera":true,"spawn_drawing":false,"spawn_emoji":true,"update_hub":false,"update_hub_promotion":false,"update_roles":false},"phx_ref":"tGJf9IxredI=","phx_ref_prev":"zJ3pFzeYafM=","presence":"room","profile":{"avatarId":"3IADk9x","displayName":"real changeling"},"roles":{"creator":false,"owner":false,"signed_in":false}}]},"774e91d5-a324-47d7-ba75-edf9ed5bbe1a":{"metas":[{"context":{"embed":false,"mobile":false},"permissions":{"close_hub":false,"embed_hub":false,"fly":true,"join_hub":true,"kick_users":false,"mute_users":false,"pin_objects":false,"spawn_and_move_media":true,"spawn_camera":true,"spawn_drawing":false,"spawn_emoji":true,"update_hub":false,"update_hub_promotion":false,"update_roles":false},"phx_ref":"NnAT0YpIaUg=","phx_ref_prev":"tzv+xV6h0Rs=","presence":"room","profile":{"avatarId":"PcJ8Sxb","displayName":"GoBotWebSockets"},"roles":{"creator":false,"owner":false,"signed_in":false}}]},"9bd22f70-521a-49c2-9cb9-ac58dabfa1d6":{"metas":[{"context":{"embed":false,"mobile":false},"permissions":{"close_hub":false,"embed_hub":false,"fly":true,"join_hub":true,"kick_users":false,"mute_users":false,"pin_objects":false,"spawn_and_move_media":true,"spawn_camera":true,"spawn_drawing":false,"spawn_emoji":true,"update_hub":false,"update_hub_promotion":false,"update_roles":false},"phx_ref":"kPknFXlNkMo=","phx_ref_prev":"IA2Es263VdA=","presence":"room","profile":{"avatarId":"3IADk9x","displayName":"killab33z"},"roles":{"creator":false,"owner":false,"signed_in":false}}]},"f87b718a-c873-40a9-99db-91b4d0f7f4de":{"metas":[{"context":{"embed":false,"mobile":false},"permissions":{"close_hub":true,"embed_hub":true,"fly":true,"join_hub":true,"kick_users":true,"mute_users":true,"pin_objects":true,"spawn_and_move_media":true,"spawn_camera":true,"spawn_drawing":true,"spawn_emoji":true,"update_hub":true,"update_hub_promotion":false,"update_roles":true},"phx_ref":"XCCt44iesAo=","presence":"lobby","profile":{"avatarId":"https://s3.amazonaws.com/readyplayerbaker/avatars_baked/89e86e1a-43c7-4520-8f91-9a94ed42a722.glb","displayName":"ReK2"},"roles":{"creator":true,"owner":true,"signed_in":true}}]}}]
with a lot of help of someone here I was able to convert a very similar one but with two I cant seem to get it to work. I keep getting empty results..
the similar approach is Here
I have tried replicating with a field above and other similar things.
I have look many blogs for this situation, no luck.
I also have try this tools, but is not really working because the tool does not know the details
edit: here is from json lint:
[
null,
null,
"hub:zWXKROOM",
"presence_state",
{
"74ce1906-af89-48a9-aec7-501369509000": {
"metas": [
{
"context": {
"embed": false,
"mobile": false
},
"permissions": {
"close_hub": false,
"embed_hub": false,
"fly": true,
"join_hub": true,
"kick_users": false,
"mute_users": false,
"pin_objects": false,
"spawn_and_move_media": true,
"spawn_camera": true,
"spawn_drawing": false,
"spawn_emoji": true,
"update_hub": false,
"update_hub_promotion": false,
"update_roles": false
},
"phx_ref": "tGJf9IxredI=",
"phx_ref_prev": "zJ3pFzeYafM=",
"presence": "room",
"profile": {
"avatarId": "3IADk9x",
"displayName": "real changeling"
},
"roles": {
"creator": false,
"owner": false,
"signed_in": false
}
}
]
},
"774e91d5-a324-47d7-ba75-edf9ed5bbe1a": {
"metas": [
{
"context": {
"embed": false,
"mobile": false
},
"permissions": {
"close_hub": false,
"embed_hub": false,
"fly": true,
"join_hub": true,
"kick_users": false,
"mute_users": false,
"pin_objects": false,
"spawn_and_move_media": true,
"spawn_camera": true,
"spawn_drawing": false,
"spawn_emoji": true,
"update_hub": false,
"update_hub_promotion": false,
"update_roles": false
},
"phx_ref": "NnAT0YpIaUg=",
"phx_ref_prev": "tzv+xV6h0Rs=",
"presence": "room",
"profile": {
"avatarId": "PcJ8Sxb",
"displayName": "GoBotWebSockets"
},
"roles": {
"creator": false,
"owner": false,
"signed_in": false
}
}
]
},
"9bd22f70-521a-49c2-9cb9-ac58dabfa1d6": {
"metas": [
{
"context": {
"embed": false,
"mobile": false
},
"permissions": {
"close_hub": false,
"embed_hub": false,
"fly": true,
"join_hub": true,
"kick_users": false,
"mute_users": false,
"pin_objects": false,
"spawn_and_move_media": true,
"spawn_camera": true,
"spawn_drawing": false,
"spawn_emoji": true,
"update_hub": false,
"update_hub_promotion": false,
"update_roles": false
},
"phx_ref": "kPknFXlNkMo=",
"phx_ref_prev": "IA2Es263VdA=",
"presence": "room",
"profile": {
"avatarId": "3IADk9x",
"displayName": "killab33z"
},
"roles": {
"creator": false,
"owner": false,
"signed_in": false
}
}
]
},
"f87b718a-c873-40a9-99db-91b4d0f7f4de": {
"metas": [
{
"context": {
"embed": false,
"mobile": false
},
"permissions": {
"close_hub": true,
"embed_hub": true,
"fly": true,
"join_hub": true,
"kick_users": true,
"mute_users": true,
"pin_objects": true,
"spawn_and_move_media": true,
"spawn_camera": true,
"spawn_drawing": true,
"spawn_emoji": true,
"update_hub": true,
"update_hub_promotion": false,
"update_roles": true
},
"phx_ref": "XCCt44iesAo=",
"presence": "lobby",
"profile": {
"avatarId": "https://s3.amazonaws.com/readyplayerbaker/avatars_baked/89e86e1a-43c7-4520-8f91-9a94ed42a722.glb",
"displayName": "ReK2"
},
"roles": {
"creator": true,
"owner": true,
"signed_in": true
}
}
]
}
}
]
[edit2]
I did a lot of multiple tries but still is not printing anything at all!
is like there is no data but there is data... can someone please check my code and see what im I doing wrong? this last one I did step by step with a tutorial, still is not even showing any data, I wish it did so at least I know what to change..
https://gitlab.com/rek2/gohubsbot/-/blob/master/websocketsListen.go
thanks
ok after a lot of debugging, reading, reading, hitting my head and stripping json to make it simples to post on json to go tools... I finally got it..
the main issue?
//the type needs to be a map itself
type PresenceState map[string]State
Also:
// even do I did try this above I never called it the right way before so was giving up and moving on... but I have to use a pointer
for k, o := range *v {}
is working now. I am getting the keys and objets when there is a presence state at login or change so I can map id to usernames

How to add tag inside a nest depending on a variable while keeping rest of json

I'm failry new to jq and I've learned to do most things on my own but I'm hitting my head on my keyboard for this one. Look at the following json
JSON:
{
"importType": "Upsert",
"immediateDeployment": false,
"isIgnoreNulls": false,
"isOverwriteNullsOnly": false,
"isPreferredandSync": false,
"outputLayout": {
"fields": [
{
"name": "TEMP_KEY",
"type": "String",
"length": "2000",
"displayName": "TEMP_KEY"
},
{
"name": "LoadSeqNum",
"type": "String",
"length": "2000",
"displayName": "LoadSeqNum"
}
]
}
}
What I'm trying to do is inside of .outputLayout.fields[] I want to create a new pair called "isIdentifier" where it is true if the .outputLayout.fields[].name is LoadSeqNum and false if it's not but I need to keep the rest of the json just as it is. So target should look as following:
Goal:
{
"importType": "Upsert",
"immediateDeployment": false,
"isIgnoreNulls": false,
"isOverwriteNullsOnly": false,
"isPreferredandSync": false,
"outputLayout": {
"fields": [
{
"name": "TEMP_KEY",
"type": "String",
"length": "2000",
"displayName": "TEMP_KEY"
"isIdentifier": false
},
{
"name": "LoadSeqNum",
"type": "String",
"length": "2000",
"displayName": "LoadSeqNum"
"isIdentifier": true
}
]
}
}
I tried this:
jq '.outputLayout.fields[] | . + {"isIdentifier": (if (.name)=="LoadSeqNum" then true else false end)}'
But of course I'm missing all the higher level things. When I try to do:
.outputLayout.fields[].isIdentifier=(if (.outputLayout.fields[].name)=="LoadSeqNum" then true else false end)
I get the whole thing twice, once with both true and the other one with both false. I understand why it's doing that but I'm having a tough time figuring out what would work. Any help or point in right direction?
.outputLayout.fields[] |= (.isIdentifier = (.displayName == "LoadSeqNum") )
Or equivalently but perhaps a little less cryptically:
.outputLayout.fields |= map( .isIdentifier = (.displayName == "LoadSeqNum") )

How i can delimite entity join level for JSON parse

I'm new to web application development with PHP, Symfony (Bundles) and Angular
we develop a web application, works over API rest building on symfony and we make request through http protocol, every response is coded in JSON.
Every JSON correspond to doctrine entity.
We use FosRest to parse entity to JSON, here my config:
fos_rest:
param_fetcher_listener: true
routing_loader:
default_format: json
include_format: json
view:
view_response_listener: 'force'
formats:
xml: false
json: true
templating_formats:
html: false
format_listener:
rules: ~
exception:
codes:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
messages:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': true
allowed_methods_listener: true
access_denied_listener:
json: true
body_listener: true
service:
inflector: app.util.inflector
Doctrine config
doctrine:
dbal:
driver: pdo_sqlsrv #pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
metadata_cache_driver: apc
query_cache_driver: apc
The generated JSON API is correct, here is an example
{
"id": 1,
"username": "admin",
"email": "admin#admin.com",
"enabled": true,
"last_login": "2016-07-04T16:31:07-0500",
"name": "admin",
"first_lastName": "admin",
"second_lastName": "admin",
"id_program": {
"id": 1,
"abbreviation": "LRI",
"nomenclature": "LRI",
"description": "Licenciatura en Relaciones Internacionales",
"consecutive": "1",
"cve_dgp": "3453454355",
"first_period": "2016-06-09T10:30:00-0500",
"campus": "HARVARD",
"mod": "Escolarizado",
"number": "863676476",
"register_date": "2016-06-09T10:30:00-0500",
"ref_number": "0976555",
"require_pay": true,
"colour_rgb": "253545454",
"last_modification": "2016-06-17T12:51:28-0500",
"id_level": {
"id": 1,
"cve": "LIC",
"description": "Licenciatura",
"last_modification": "2016-06-11T10:58:44-0500",
"id_status": {
"id": 1008,
"value": "Inactivo",
"active": true,
"id_cat": {
"id": 1004,
"valur": "CatalogosEstatus",
"active": true
}
}
},
"id_front_credenctial_file": {
"id": 193,
"name": "FRENTE-LRI.jpg",
"extention": "jpeg",
"mime_type": "image/jpeg",
"md5": "e5643b567aa6e134ae1abcc23fdb545e",
"is_perfil": false
},
"id_back_file_credential": {
"id": 194,
"name": "REVES-LRI.jpg",
"extention": "jpeg",
"mime_type": "image/jpeg",
"md5": "d490d35f448d3fcb849cc708f7291bc5",
"is_perfil": false
},
"id_status": {
"id": 1007,
"value": "Activo",
"active": true,
"id_cat": {
"id": 1004,
"value": "CatalogosEstatus",
"active": true
}
}
},
"ldap": true,
"rolesdb": [{
"id": 8,
"id_rol": {
"id": 9,
"name": "ADMINISTRADOR",
"description": "Rol Administrador",
"active": true
}
}, {
"id": 9,
"id_rol": {
"id": 10,
"name": "SHOWCASE",
"description": "Rol showcase",
"active": true
}
}, {
"id": 10,
"id_rol": {
"id": 11,
"name": "DESARROLLADOR",
"description": "Rol desarrollador",
"active": true
}
}]}
The problem I have is when an entity has multiple relationships , as you can see in the JSON example , when parsing the entity being added all your relationships (each key that starts with id_ is a mapped relationship with Doctrine) and as our BD has grown considerably , there are times when a JSON has too much information that is hard to read from Angular side .
Is there a way to define (optimize ) until the parser level (JSON ) relations is made in an entity ?
or not include each join of the entity?
regards!!
with #MaxDepth you can steer how deep you want to serialize your hierarchy and with #Groups you can manage which fields should be serialized.
Both can be set in your Serialization Context and are explained in more detail in the FOS Rest Documentation
By that you should be able to achieve what you're looking for.