How to compare the fields present in two json response and validate it? - rest-assured

I need to compare all the countries present in Response1 should be present in Response2 also.
So How Can I take all the countries from both the responses and validate?
I tried on storing country in ArrayList but not able to validate it.
Json Response 1:
{
"plan": {
"program": "gtr",
"syter": "yes"
},
"Map": {
"List": [
{
"id": "tyt6577",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "us",
"triag": null
},
{
"id": "yyaqtf6327",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "aus",
"triag": null
},
{
"id": "676hwjsgvhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "rus",
"triag": null
},
{
"id": "676hsdhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "spa",
"triag": null
},
{
"id": "623ujhhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "cha",
"triag": null
}
]
}
}
Json Response 2:
[
{
"id": "tyt6577",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "rus",
"triag": null
},
{
"id": "yyaqtf6327",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "spa",
"triag": null
},
{
"id": "676hwjsgvhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "us",
"triag": null
},
{
"id": "676hsdhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "aus",
"triag": null
},
{
"id": "623ujhhgv",
"proxy": "ENABLED",
"type": "BENEFIT",
"country": "cha",
"triag": null
}
]

This would work for you
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
...
List<String> country = res.jsonPath().get("Map.List.country");
List<String> country2 = res2.jsonPath().get("country");
assertThat(country2, containsInAnyOrder(country.toArray()));

Related

Avro multiple enum int the same type (avro.SchemaParseException: Can't redefine)

A have the following avro schema, but if I want to parse it, then I got the following error:
Exception in thread "main" org.apache.avro.SchemaParseException: Can't redefine: ...
{
"name": "card_1_nr",
"type": "string"
}, {
"name": "card_1_type",
"type": {
"name": "card_type",
"type": "enum",
"symbols": ["diamonds", "clubs", "hearts", "spades"],
"default": "diamonds"
}
}, {
"name": "card_2_nr",
"type": "string"
}, {
"name": "card_2_type",
"type": {
"name": "card_type",
"type": "enum",
"symbols": ["diamonds", "clubs", "hearts", "spades"],
"default": "diamonds"
}
}
Just simply need to use the enume type name:
{
"name": "card_1_nr",
"type": "string"
}, {
"name": "card_1_type",
"type": {
"name": "card_type",
"type": "enum",
"symbols": ["diamonds", "clubs", "hearts", "spades"],
"default": "diamonds"
}
}, {
"name": "card_2_nr",
"type": "string"
}, {
"name": "card_2_type",
"type": "card_type"
}

confluent_kafka.error.ValueSerializationError: KafkaError{code=_VALUE_SERIALIZATION,val=-161 : ValueError

I am new bee to python and trying to use 'confluent_kafka' for avro message produce.
Using 'confluent_kafka.schema_registry.avro.AvroSerializer' for the same
(referred : https://github.com/confluentinc/confluent-kafka-python/blob/master/examples/avro_producer.py)
It works for simple avro schema with dict(json converted to dict) input, but for below sample schema I am getting error :
Schema :
{
"type": "record",
"name": "Envelope",
"namespace": "CoreOLTPEvents.dbo.Event",
"fields": [{
"name": "before",
"type": ["null", {
"type": "record",
"name": "Value",
"fields": [{
"name": "EventId",
"type": "long"
}, {
"name": "CameraId",
"type": ["null", "long"],
"default": null
}],
"connect.name": "CoreOLTPEvents.dbo.Event.Value"
}],
"default": null
}, {
"name": "after",
"type": ["null", "Value"],
"default": null
}, {
"name": "source",
"type": {
"type": "record",
"name": "Source",
"namespace": "io.debezium.connector.sqlserver",
"fields": [{
"name": "version",
"type": "string"
}, {
"name": "connector",
"type": "string"
}],
"connect.name": "io.debezium.connector.sqlserver.Source"
}
}, {
"name": "op",
"type": "string"
}],
"connect.name": "CoreOLTPEvents.dbo.Event.Envelope"
}
Input Json :
{
"after": null,
"before": {
"CoreOLTPEvents.dbo.Event.Value" : {
"EventId": 1111111111,
"CameraId": 222222222
}
},
"source": {
"version": "InitialLoad",
"connector": "sqlserver"
},
"op": "C"
}
Error :
ValueError: {'CoreOLTPEvents.dbo.Event.Value': {'EventId': 1111111111, 'CameraId': 222222222}} (type <class 'dict'>) do not match ['null', {'connect.name': 'CoreOLTPEvents.dbo.Event.Value', 'type': 'record', 'name': 'CoreOLTPEvents.dbo.Event.Value', 'fields': [{'name': 'EventId', 'type': 'long'}, {'default': None, 'name': 'CameraId', 'type': ['null', 'long']}]}] on field before
'before' field type is union (['null',record]), if I change it to only record (remove union) then it works fine.
But I need to adjust my input such a way that it works for given schema.
(Note : I am reading json input using 'json.load(json_file)' so it gives dict output)
Any help would be much appreciated.
Update :
Actual large schema :
{
"type": "record",
"name": "Envelope",
"namespace": "CoreOLTPEvents.dbo.Event",
"fields": [{
"name": "before",
"type": ["null", {
"type": "record",
"name": "Value",
"fields": [{
"name": "EventId",
"type": "long"
}, {
"name": "CameraId",
"type": ["null", "long"],
"default": null
}, {
"name": "SiteId",
"type": ["null", "long"],
"default": null
}, {
"name": "VehicleId",
"type": ["null", "long"],
"default": null
}, {
"name": "EventReviewStatusID",
"type": "int"
}, {
"name": "EventTypeId",
"type": ["null", "int"],
"default": null
}, {
"name": "EventDateTime",
"type": ["null", {
"type": "string",
"connect.name": "net.smartdrive.converters.SmartdriveEventDateFieldConverter"
}],
"default": null
}, {
"name": "FTPUploadDateTime",
"type": {
"type": "long",
"connect.version": 1,
"connect.name": "io.debezium.time.Timestamp"
}
}, {
"name": "CAMFileName",
"type": "string"
}, {
"name": "KeypadEntryCode",
"type": ["null", "string"],
"default": null
}, {
"name": "IsActive",
"type": {
"type": "boolean",
"connect.default": true
},
"default": true
}, {
"name": "Flagged",
"type": "boolean"
}, {
"name": "EventTitle",
"type": ["null", "string"],
"default": null
}, {
"name": "CreatedBy",
"type": "long"
}, {
"name": "CreatedDate",
"type": {
"type": "long",
"connect.version": 1,
"connect.name": "io.debezium.time.Timestamp"
}
}, {
"name": "ModifiedBy",
"type": "long"
}, {
"name": "ModifiedDate",
"type": {
"type": "long",
"connect.version": 1,
"connect.name": "io.debezium.time.Timestamp"
}
}, {
"name": "ReReviewAnalysis",
"type": ["null", "string"],
"default": null
}, {
"name": "LegacyEventId",
"type": ["null", "long"],
"default": null
}, {
"name": "TripId",
"type": ["null", "long"],
"default": null
}, {
"name": "FileVersion",
"type": ["null", "string"],
"default": null
}, {
"name": "EventNumber",
"type": ["null", "string"],
"default": null
}, {
"name": "Latitude",
"type": ["null", {
"type": "bytes",
"scale": 10,
"precision": 13,
"connect.version": 1,
"connect.parameters": {
"scale": "10",
"connect.decimal.precision": "13"
},
"connect.name": "org.apache.kafka.connect.data.Decimal",
"logicalType": "decimal"
}],
"default": null
}, {
"name": "Longitude",
"type": ["null", {
"type": "bytes",
"scale": 10,
"precision": 13,
"connect.version": 1,
"connect.parameters": {
"scale": "10",
"connect.decimal.precision": "13"
},
"connect.name": "org.apache.kafka.connect.data.Decimal",
"logicalType": "decimal"
}],
"default": null
}, {
"name": "GeoAddressId",
"type": ["null", "long"],
"default": null
}, {
"name": "ReviewedEventId",
"type": ["null", "long"],
"default": null
}, {
"name": "VideoStatus",
"type": {
"type": "int",
"connect.default": 0
},
"default": 0
}, {
"name": "PredictionImportance",
"type": ["null", {
"type": "bytes",
"scale": 10,
"precision": 15,
"connect.version": 1,
"connect.parameters": {
"scale": "10",
"connect.decimal.precision": "15"
},
"connect.name": "org.apache.kafka.connect.data.Decimal",
"logicalType": "decimal"
}],
"default": null
}, {
"name": "FlaggedBy",
"type": ["null", "long"],
"default": null
}, {
"name": "FlaggedDate",
"type": ["null", {
"type": "long",
"connect.version": 1,
"connect.name": "io.debezium.time.Timestamp"
}],
"default": null
}, {
"name": "TriggerTypeId",
"type": ["null", "int"],
"default": null
}, {
"name": "VideoDeleteDate",
"type": ["null", {
"type": "long",
"connect.version": 1,
"connect.name": "io.debezium.time.Timestamp"
}],
"default": null
}, {
"name": "MetadataDeleteDate",
"type": ["null", {
"type": "long",
"connect.version": 1,
"connect.name": "io.debezium.time.Timestamp"
}],
"default": null
}, {
"name": "RetentionStatus",
"type": {
"type": "int",
"connect.default": 0,
"connect.type": "int16"
},
"default": 0
}, {
"name": "PartnerTriggerId",
"type": ["null", "int"],
"default": null
}, {
"name": "CoachingStateId",
"type": {
"type": "int",
"connect.default": 0,
"connect.type": "int16"
},
"default": 0
}, {
"name": "EventKudoHistoryId",
"type": ["null", "int"],
"default": null
}],
"connect.name": "CoreOLTPEvents.dbo.Event.Value"
}],
"default": null
}, {
"name": "after",
"type": ["null", "Value"],
"default": null
}, {
"name": "source",
"type": {
"type": "record",
"name": "Source",
"namespace": "io.debezium.connector.sqlserver",
"fields": [{
"name": "version",
"type": "string"
}, {
"name": "connector",
"type": "string"
}, {
"name": "name",
"type": "string"
}, {
"name": "ts_ms",
"type": "long"
}, {
"name": "snapshot",
"type": [{
"type": "string",
"connect.version": 1,
"connect.parameters": {
"allowed": "true,last,false"
},
"connect.default": "false",
"connect.name": "io.debezium.data.Enum"
}, "null"],
"default": "false"
}, {
"name": "db",
"type": "string"
}, {
"name": "schema",
"type": "string"
}, {
"name": "table",
"type": "string"
}, {
"name": "change_lsn",
"type": ["null", "string"],
"default": null
}, {
"name": "commit_lsn",
"type": ["null", "string"],
"default": null
}, {
"name": "event_serial_no",
"type": ["null", "long"],
"default": null
}],
"connect.name": "io.debezium.connector.sqlserver.Source"
}
}, {
"name": "op",
"type": "string"
}, {
"name": "ts_ms",
"type": ["null", "long"],
"default": null
}, {
"name": "transaction",
"type": ["null", {
"type": "record",
"name": "ConnectDefault",
"namespace": "io.confluent.connect.avro",
"fields": [{
"name": "id",
"type": "string"
}, {
"name": "total_order",
"type": "long"
}, {
"name": "data_collection_order",
"type": "long"
}]
}],
"default": null
}],
"connect.name": "CoreOLTPEvents.dbo.Event.Envelope"
}
Input for large schema :
{
"before": null,
"after": {
"EventId": 1234566,
"CameraId": 2233,
"SiteId": 111,
"VehicleId": 45587,
"EventReviewStatusID": 10,
"EventTypeId": 123,
"EventDateTime": "2015-01-02T01:30:29Z",
"FTPUploadDateTime": 1420193330590,
"CAMFileName": "XYZ",
"KeypadEntryCode": "0",
"IsActive": false,
"Flagged": false,
"EventTitle": null,
"CreatedBy": 1,
"CreatedDate": 1420191120730,
"ModifiedBy": 1,
"ModifiedDate": 1577871185680,
"ReReviewAnalysis": null,
"LegacyEventId": null,
"TripId": 3382,
"FileVersion": "2.2",
"EventNumber": "AAAA-BBBB",
"Latitude": "UU9elrA=",
"Longitude": "/ueZUeFw",
"GeoAddressId": null,
"ReviewedEventId": 129411077,
"VideoStatus": 4,
"PredictionImportance": 0.1402457539,
"FlaggedBy": null,
"FlaggedDate": null,
"TriggerTypeId": 322,
"VideoDeleteDate": 1422783120000,
"MetadataDeleteDate": 1577871120000,
"RetentionStatus": 15,
"PartnerTriggerId": null,
"CoachingStateId": 0,
"EventKudoHistoryId": null
},
"source": {
"version": "Final",
"connector": "sqlserver",
"name": "CoreOLTP",
"ts_ms": 1615813992548,
"snapshot": "false",
"db": "CoreOLTP",
"schema": "dbo",
"table": "xyz",
"change_lsn": null,
"commit_lsn": null,
"event_serial_no": null
},
"op": "C",
"ts_ms": 1615813992548,
"transaction": null
}
Error :
confluent_kafka.error.ValueSerializationError: KafkaError{code=_VALUE_SERIALIZATION,val=-161,str="{'EventId': 129411077, 'CameraId': 46237, 'SiteId': 2148, 'VehicleId': 45587, 'EventReviewStatusID': 10, 'EventTypeId': 247, 'EventDateTime': '2015-01-02T01:30:29Z', 'FTPUploadDateTime': 1420191120590, 'CAMFileName': 'JD2BC02120150102013029ER.SDE', 'KeypadEntryCode': '0', 'IsActive': False, 'Flagged': False, 'EventTitle': None, 'CreatedBy': 1, 'CreatedDate': 1420191120730, 'ModifiedBy': 1, 'ModifiedDate': 1577871185680, 'ReReviewAnalysis': None, 'LegacyEventId': None, 'TripId': 3382, 'FileVersion': '2.2', 'EventNumber': 'WSHX-8QQ2', 'Latitude': 'UU9elrA=', 'Longitude': '/ueZUeFw', 'GeoAddressId': None, 'ReviewedEventId': 129411077, 'VideoStatus': 4, 'PredictionImportance': 0.1402457539, 'FlaggedBy': None, 'FlaggedDate': None, 'TriggerTypeId': 322, 'VideoDeleteDate': 1422783120000, 'MetadataDeleteDate': 1577871120000, 'RetentionStatus': 15, 'PartnerTriggerId': None, 'CoachingStateId': 0, 'EventKudoHistoryId': None} (type <class 'dict'>) do not match ['null', 'CoreOLTPEvents.dbo.Event.Value'] on field after"}
You just need to change your input so that the before field doesn't have the namespace. So it needs to look like this:
{
"after": null,
"before": {
"EventId": 1111111111,
"CameraId": 222222222
},
"source": {
"version": "InitialLoad",
"connector": "sqlserver"
},
"op": "C"
}
The original input you had looked like it was trying to be JSON encoded avro because the field before had the CoreOLTPEvents.dbo.Event.Value namespace. However, I'm guessing it must have been hand crafted because CameraId should have been specified as {"long": 222222222} rather than just 222222222.
If you do actually have Avro encoded JSON (from the result of some other process or something) then you you could use something like fastavro.json_reader to read in that file and it will create the correct memory representation (that doesn't include the type information for union fields).
UPDATE:
To figure out what the problem is with the full schema and full data, I first loaded the two objects using json.load and then used fastavro.validate(record, schema) The output from that is a stacktrace that ends with this:
fastavro._validate_common.ValidationError: [
"CoreOLTPEvents.dbo.Event.Envelope.after is <{'EventId': 1234566, 'CameraId': 2233, 'SiteId': 111, 'VehicleId': 45587, 'EventReviewStatusID': 10, 'EventTypeId': 123, 'EventDateTime': '2015-01-02T01:30:29Z', 'FTPUploadDateTime': 1420193330590, 'CAMFileName': 'XYZ', 'KeypadEntryCode': '0', 'IsActive': False, 'Flagged': False, 'EventTitle': None, 'CreatedBy': 1, 'CreatedDate': 1420191120730, 'ModifiedBy': 1, 'ModifiedDate': 1577871185680, 'ReReviewAnalysis': None, 'LegacyEventId': None, 'TripId': 3382, 'FileVersion': '2.2', 'EventNumber': 'AAAA-BBBB', 'Latitude': 'UU9elrA=', 'Longitude': '/ueZUeFw', 'GeoAddressId': None, 'ReviewedEventId': 129411077, 'VideoStatus': 4, 'PredictionImportance': 0.1402457539, 'FlaggedBy': None, 'FlaggedDate': None, 'TriggerTypeId': 322, 'VideoDeleteDate': 1422783120000, 'MetadataDeleteDate': 1577871120000, 'RetentionStatus': 15, 'PartnerTriggerId': None, 'CoachingStateId': 0, 'EventKudoHistoryId': None}> of type <class 'dict'> expected null",
"CoreOLTPEvents.dbo.Event.Value.Latitude is <UU9elrA=> of type <class 'str'> expected null",
"CoreOLTPEvents.dbo.Event.Value.Latitude is <UU9elrA=> of type <class 'str'> expected {'scale': 10, 'precision': 13, 'connect.version': 1, 'connect.parameters': {'scale': '10', 'connect.decimal.precision': '13'}, 'connect.name': 'org.apache.kafka.connect.data.Decimal', 'logicalType': 'decimal', 'type': 'bytes'}"
]
So that is trying to tell us that there is 3 potential problems. The first is that the value in after doesn't match null, but we can ignore that because we don't want after to match null.
The later two problems are the actual problem. It says that the value of Latitude is the string UU9elrA=, but that doesn't match either null or bytes. The string here looks base64 encoded, so maybe you have some code that decodes that to bytes and if so then maybe the actual problem is something else, but if so then I think you should be able to use fastavro.validate to figure out what the problem is.

How to use a dictionary from JSON with Realm?

Creating a data model to use with codable and realm. Im getting stuck on dictionaries. As I understand it, you cannot use dictionaries with realm? How can I decode the following JSON and use it with something Realm will accept?
JSON Example A
"platform": {
"data": {
"25": {
"id": 25,
"name": "3DO",
"alias": "3do"
},
"4944": {
"id": 4944,
"name": "Acorn Archimedes",
"alias": "acorn-archimedes"
},
"4954": {
"id": 4954,
"name": "Acorn Electron",
"alias": "acorn-electron"
}
}
Note, the keys are strings that change, in decoable form i have it as
StructExample A
struct PlatformData : Codable {
let data : [String: PlatformInformation]
}
JSON Example B
"include": {
"boxart": {
"base_url": {
"original": "https:\/\/cdn.thegamesdb.net\/images\/original\/",
"small": "https:\/\/cdn.thegamesdb.net\/images\/small\/",
"thumb": "https:\/\/cdn.thegamesdb.net\/images\/thumb\/",
"cropped_center_thumb": "https:\/\/cdn.thegamesdb.net\/images\/cropped_center_thumb\/",
"medium": "https:\/\/cdn.thegamesdb.net\/images\/medium\/",
"large": "https:\/\/cdn.thegamesdb.net\/images\/large\/"
},
"data": {
"1":
[
{
"id": 242,
"type": "fanart",
"side": null,
"filename": "fanart\/1-2.jpg",
"resolution": "1920x1080"
},
{
"id": 433,
"type": "fanart",
"side": null,
"filename": "fanart\/1-5.jpg",
"resolution": "1920x1080"
}
],
"2":
[
{
"id": 15,
"type": "fanart",
"side": null,
"filename": "fanart\/2-1.jpg",
"resolution": "1920x1080"
},
{
"id": 133,
"type": "fanart",
"side": null,
"filename": "fanart\/2-2.jpg",
"resolution": "1920x1080"
},
{
"id": 656,
"type": "fanart",
"side": null,
"filename": "fanart\/2-4.jpg",
"resolution": "1920x1080"
}
],
"4":
[
{
"id": 208,
"type": "fanart",
"side": null,
"filename": "fanart\/4-1.jpg",
"resolution": "1920x1080"
},
{
"id": 481,
"type": "banner",
"side": null,
"filename": "graphical\/4-g.jpg",
"resolution": null
},
{
"id": 846,
"type": "boxart",
"side": "front",
"filename": "boxart\/front\/4-1.jpg",
"resolution": "1000x705"
},
{
"id": 847,
"type": "boxart",
"side": "back",
"filename": "boxart\/back\/4-1.jpg",
"resolution": "1000x705"
},
{
"id": 73897,
"type": "clearlogo",
"side": null,
"filename": "clearlogo\/4.png",
"resolution": "400x148"
},
{
"id": 215539,
"type": "fanart",
"side": null,
"filename": "fanart\/4-2.jpg",
"resolution": null
},
{
"id": 238533,
"type": "screenshot",
"side": null,
"filename": "screenshot\/4-1.jpg",
"resolution": null
},
{
"id": 238534,
"type": "screenshot",
"side": null,
"filename": "screenshot\/4-2.jpg",
"resolution": null
},
{
"id": 238535,
"type": "screenshot",
"side": null,
"filename": "screenshot\/4-3.jpg",
"resolution": null
},
{
"id": 238536,
"type": "screenshot",
"side": null,
"filename": "screenshot\/4-4.jpg",
"resolution": null
},
{
"id": 238537,
"type": "screenshot",
"side": null,
"filename": "screenshot\/4-5.jpg",
"resolution": null
},
{
"id": 238538,
"type": "screenshot",
"side": null,
"filename": "screenshot\/4-6.jpg",
"resolution": null
}
],
"5":
[
{
"id": 396,
"type": "banner",
"side": null,
"filename": "graphical\/5-g.jpg",
"resolution": null
},
{
"id": 2364,
"type": "fanart",
"side": null,
"filename": "fanart\/5-4.jpg",
"resolution": "1920x1080"
},
]
Here is similar, except now with an array of objects as the value
Struct Example B
struct BoxArtData : Codeable {
let data: [String:[ExtraImages]]
}

Swagger 2.0 - Inconsistent Results From Swagger Source

Swagger source below. When I run the swagger-tools validator, I receive no errors. When I load this in the editor, I see output but it is incorrect - it shows wrong types, and an incomplete Member object. When I try to use the code generator cli java tool, I get the following errors:
711 [main] ERROR io.swagger.models.properties.PropertyBuilder - no property for null, null
712 [main] WARN io.swagger.util.PropertyDeserializer - no property from null, null, {ENUM=null, TITLE=null, DESCRIPTION=null, DEFAULT=null, PATTERN=null, DESCRIMINATOR=null, MIN_ITEMS=null, MAX_ITEMS=null, MIN_PROPERTIES=null, MAX_PROPERTIES=null, MIN_LENGTH=null, MAX_LENGTH=null, MINIMUM=null, MAXIMUM=null, EXCLUSIVE_MINIMUM=null, EXCLUSIVE_MAXIMUM=null, UNIQUE_ITEMS=null, EXAMPLE=null, TYPE=null, FORMAT=null}
822 [main] ERROR io.swagger.codegen.DefaultCodegen - unexpected missing property for name null
822 [main] WARN io.swagger.codegen.DefaultCodegen - skipping invalid property {
"type" : "array"
}
{
"swagger": "2.0",
"info": {
"title": "V1 Inmar CRM API",
"description": "CRM API",
"version": "1.0.0"
},
"produces": ["application/json"],
"basePath": "/v1",
"paths": {
"/member": {
"get": {
"x-swagger-router-controller": "member",
"tags": ["member"],
"operationId": "GetMember",
"parameters": [
{ "$ref": "#/parameters/x-inmar-rest-api-key" },
{ "$ref": "#/parameters/x-inmar-memberID" }
],
"responses": {
"200": {
"description": "success",
"schema": { "$ref": "#/definitions/Member" }
}
}
},
"post": {
"x-swagger-route-controller": "member",
"tags": ["member"],
"operationId": "PostMember",
"parameters": [
{ "$ref": "#/parameters/x-inmar-rest-api-key" },
{ "$ref": "#/parameters/x-inmar-memberID" },
{ "$ref": "#/parameters/member" }
],
"responses": {
"200": { "$ref": "#/responses/generic-200" }
}
}
}
},
"parameters": {
"x-inmar-rest-api-key": {
"name": "X-Inmar-REST-API-Key",
"description": "API Access Key.",
"in": "header",
"required": true,
"type": "string"
},
"x-inmar-memberID": {
"name": "X-Inmar-MemberID",
"description": "Unique ID for member.",
"in": "header",
"required": true,
"type": "string"
},
"member": {
"description": "member object",
"in": "body",
"name": "body",
"required": true,
"schema": {
"$ref": "#/definitions/Member"
}
}
},
"responses": {
"generic-200": {
"description": "Success"
}
},
"definitions": {
"Member": {
"description": "member",
"type": "object",
"properties": {
"active": {
"type": "boolean",
"default": true
},
"identity": {
"type": "object",
"required": [
"user_id"
],
"properties": {
"user_id": {
"type": "string",
"maxLength": 50,
"format": "email"
},
"password": {
"type": "string",
"minLength": 8,
"maxLength": 20
},
"proxy_id": {
"type": "integer"
}
}
},
"pii": {
"type": "object",
"description": "personally_identifiable_information.",
"properties": {
"alt_email": {
"type": "string",
"description": "Secondary email addresses that may or may not match the id.",
"format": "email"
},
"first_name": {
"type": "string",
"minLength": 1,
"maxLength": 25
},
"last_name": {
"type": "string",
"minLength": 1,
"maxLength": 25
},
"primary_address_one": {
"type": "string",
"minLength": 1,
"maxLength": 47
},
"primary_address_two": {
"type": "string",
"minLength": 1,
"maxLength": 47
},
"primary_address_city": {
"type": "string",
"minLength": 1,
"maxLength": 47
},
"primary_address_state": {
"type": "string",
"minLength": 2,
"maxLength": 2,
"description": "US states and US territories and Canadian provinces.",
"enum": [
"AA",
"AB",
"AE",
"AK",
"AL",
"AP",
"AR",
"AS",
"AZ",
"BC",
"CA",
"CO",
"CT",
"DC",
"DE",
"FL",
"FM",
"GA",
"GU",
"HI",
"IA",
"ID",
"IL",
"IN",
"KS",
"KY",
"LA",
"MA",
"MB",
"MD",
"ME",
"MH",
"MI",
"MN",
"MO",
"MP",
"MS",
"MT",
"NB",
"NC",
"ND",
"NE",
"NH",
"NJ",
"NL",
"NM",
"NS",
"NT",
"NU",
"NV",
"NY",
"OH",
"OK",
"ON",
"OR",
"PA",
"PE",
"PR",
"PW",
"QC",
"RI",
"SC",
"SD",
"SK",
"TN",
"TX",
"UK",
"UT",
"VA",
"VI",
"VT",
"WA",
"WI",
"WV",
"WY",
"YT"
]
},
"primary_address_postal_code": {
"type": "string",
"minLength": 5,
"maxLength": 10
},
"primary_address_country": {
"type": "string",
"enum": [
"US",
"CA"
]
},
"birthdate": {
"type": "string"
},
"language_preference": {
"type": "string"
},
"gender": {
"type": "string",
"enum": [
"male",
"female"
]
}
}
},
"profiles": {
"type": "array",
"items": {
"properties": {
"site_id": {
"type": "integer"
},
"survey_data": {
"type": "object",
"required": [
"survey_id",
"survey_responses"
],
"properties": {
"survey_id": {
"type": "integer",
"description": "Unique identifier of a profile survey."
},
"survey_responses": {
"type": "array",
"items": {
"required": [
"question_id",
"response_id",
"free_form_value"
],
"properties": {
"question_id": {
"type": "integer",
"description": "Unique identifier of a profile survey question."
},
"response_id": {
"type": "integer",
"description": "Unique identifier of a profile question response.",
"default": 0
},
"free_form_value": {
"type": "string",
"description": "Consumer free form response",
"default": ""
}
}
}
}
}
}
}
}
},
"optins": {
"type": "array",
"items": {
"$ref": "#/definitions/OptIn"
}
}
}
},
"OptIn": {
"description": "survey response",
"type": "object",
"properties":{
"optin_id": {
"type": "integer",
"description": "Unique identifier of an opt in question/choice. e.g. newsletter"
},
"optin_value": {
"type": "integer",
"enum": [ 0, 1 ],
"description": "Optin Response of 0=Optout and 1=Optin"
}
},
"required": [
"optin_id",
"optin_value"
]
}
}
}

Parse this input

I get this text from the quizlet API. But how do I proceed to import it and cut it into usable pieces. I tried NSXMLParser but it didn't work. (Error 111).
How do I parse this input?
I don't need specific instructions, but a hint to where to search would be awesome.
{
"id": 415,
"url": "http://quizlet.com/415/us-state-capitals-flash-cards/",
"title": "U.S. State Capitals",
"created_by": "asuth",
"term_count": 50,
"created_date": 1144296408,
"modified_date": 1393464052,
"has_images": false,
"subjects": [
],
"visibility": "public",
"editable": "only_me",
"has_access": true,
"description": "",
"lang_terms": "en",
"lang_definitions": "en",
"has_discussion": false,
"creator": {
"username": "asuth",
"account_type": "plus",
"profile_image": "https://fbquizlet-quizletllc.netdna-ssl.com/hprofile-ak-ash1/t5/203061_1030920097_793938339_n.jpg",
"id": 1
},
],
"terms": [
{
"id": 1277349735,
"term": "Montgomery",
"definition": "Alabama",
"image": null
},
{
"id": 842513565,
"term": "Juneau",
"definition": "Alaska",
"image": null
},
{
"id": 413281845,
"term": "Phoenix",
"definition": "Arizona",
"image": null
},
{
"id": 413281846,
"term": "Little Rock",
"definition": "Arkansas",
"image": null
},
{
"id": 413281847,
"term": "Sacramento",
"definition": "California",
"image": null
},
{
"id": 413281848,
"term": "Denver",
"definition": "Colorado",
"image": null
},
{
"id": 413281849,
"term": "Hartford",
"definition": "Connecticut",
"image": null
},
{
"id": 413281850,
"term": "Dover",
"definition": "Delaware",
"image": null
},
{
"id": 413281851,
"term": "Tallahassee",
"definition": "Florida",
"image": null
},
{
"id": 413281852,
"term": "Atlanta",
"definition": "Georgia",
"image": null
},
{
"id": 413281853,
"term": "Honolulu",
"definition": "Hawaii",
"image": null
},
{
"id": 413281854,
"term": "Boise",
"definition": "Idaho",
"image": null
},
{
"id": 413281855,
"term": "Springfield",
"definition": "Illinois",
"image": null
},
{
"id": 413281856,
"term": "Indianapolis",
"definition": "Indiana",
"image": null
},
{
"id": 413281857,
"term": "Des Moines",
"definition": "Iowa",
"image": null
},
{
"id": 413281858,
"term": "Topeka",
"definition": "Kansas",
"image": null
},
{
"id": 413281859,
"term": "Frankfort",
"definition": "Kentucky",
"image": null
},
{
"id": 413281860,
"term": "Baton Rouge",
"definition": "Louisiana",
"image": null
},
{
"id": 413281861,
"term": "Augusta",
"definition": "Maine",
"image": null
},
{
"id": 413281862,
"term": "Annapolis",
"definition": "Maryland",
"image": null
},
{
"id": 413281863,
"term": "Boston",
"definition": "Massachusetts",
"image": null
},
{
"id": 413281864,
"term": "Lansing",
"definition": "Michigan",
"image": null
},
{
"id": 413281865,
"term": "St. Paul",
"definition": "Minnesota",
"image": null
},
{
"id": 413281866,
"term": "Jackson",
"definition": "Mississippi",
"image": null
},
{
"id": 413281867,
"term": "Jefferson City",
"definition": "Missouri",
"image": null
},
{
"id": 413281868,
"term": "Helena",
"definition": "Montana",
"image": null
},
{
"id": 413281869,
"term": "Lincoln",
"definition": "Nebraska",
"image": null
},
{
"id": 413281870,
"term": "Carson City",
"definition": "Nevada",
"image": null
},
{
"id": 413281871,
"term": "Concord",
"definition": "New Hampshire",
"image": null
},
{
"id": 413281872,
"term": "Trenton",
"definition": "New Jersey",
"image": null
},
{
"id": 413281873,
"term": "Santa Fe",
"definition": "New Mexico",
"image": null
},
{
"id": 413281874,
"term": "Albany",
"definition": "New York",
"image": null
},
{
"id": 413281875,
"term": "Raleigh",
"definition": "North Carolina",
"image": null
},
{
"id": 413281876,
"term": "Bismarck",
"definition": "North Dakota",
"image": null
},
{
"id": 413281877,
"term": "Columbus",
"definition": "Ohio",
"image": null
},
{
"id": 413281878,
"term": "Oklahoma City",
"definition": "Oklahoma",
"image": null
},
{
"id": 413281879,
"term": "Salem",
"definition": "Oregon",
"image": null
},
{
"id": 413281880,
"term": "Harrisburg",
"definition": "Pennsylvania",
"image": null
},
{
"id": 413281881,
"term": "Providence",
"definition": "Rhode Island",
"image": null
},
{
"id": 413281882,
"term": "Columbia",
"definition": "South Carolina",
"image": null
},
{
"id": 413281883,
"term": "Pierre",
"definition": "South Dakota",
"image": null
},
{
"id": 413281884,
"term": "Nashville",
"definition": "Tennessee",
"image": null
},
{
"id": 413281885,
"term": "Austin",
"definition": "Texas",
"image": null
},
{
"id": 413281886,
"term": "Salt Lake City",
"definition": "Utah",
"image": null
},
{
"id": 413281887,
"term": "Montpelier",
"definition": "Vermont",
"image": null
},
{
"id": 413281888,
"term": "Richmond",
"definition": "Virginia",
"image": null
},
{
"id": 413281889,
"term": "Olympia",
"definition": "Washington",
"image": null
},
{
"id": 413281890,
"term": "Charleston",
"definition": "West Virginia",
"image": null
},
{
"id": 413281891,
"term": "Madison",
"definition": "Wisconsin",
"image": null
},
{
"id": 413281892,
"term": "Cheyenne",
"definition": "Wyoming",
"image": null
}
]
}
https://api.quizlet.com/2.0/sets/415?access_token=Nzk0NzEzOGZmOTNjZDY3YmIyNTI1YTA0ZmU4NTQ1&whitespace=1
My assumption is that this part is what you are after:
"terms": [
{
"id": 1277349735,
"term": "Montgomery",
"definition": "Alabama",
"image": null
},
{
"id": 842513565,
"term": "Juneau",
"definition": "Alaska",
"image": null
},
{
"id": 413281845,
"term": "Phoenix",
"definition": "Arizona",
"image": null
},
{
"id": 413281846,
"term": "Little Rock",
"definition": "Arkansas",
"image": null
},
{
"id": 413281847,
"term": "Sacramento",
"definition": "California",
"image": null
},
{
"id": 413281848,
"term": "Denver",
"definition": "Colorado",
"image": null
},
{
"id": 413281849,
"term": "Hartford",
"definition": "Connecticut",
"image": null
},
{
"id": 413281850,
"term": "Dover",
"definition": "Delaware",
"image": null
},
{
"id": 413281851,
"term": "Tallahassee",
"definition": "Florida",
"image": null
},
{
"id": 413281852,
"term": "Atlanta",
"definition": "Georgia",
"image": null
},
{
"id": 413281853,
"term": "Honolulu",
"definition": "Hawaii",
"image": null
},
{
"id": 413281854,
"term": "Boise",
"definition": "Idaho",
"image": null
},
{
"id": 413281855,
"term": "Springfield",
"definition": "Illinois",
"image": null
},
{
"id": 413281856,
"term": "Indianapolis",
"definition": "Indiana",
"image": null
},
{
"id": 413281857,
"term": "Des Moines",
"definition": "Iowa",
"image": null
},
{
"id": 413281858,
"term": "Topeka",
"definition": "Kansas",
"image": null
},
{
"id": 413281859,
"term": "Frankfort",
"definition": "Kentucky",
"image": null
},
{
"id": 413281860,
"term": "Baton Rouge",
"definition": "Louisiana",
"image": null
},
{
"id": 413281861,
"term": "Augusta",
"definition": "Maine",
"image": null
},
{
"id": 413281862,
"term": "Annapolis",
"definition": "Maryland",
"image": null
},
{
"id": 413281863,
"term": "Boston",
"definition": "Massachusetts",
"image": null
},
{
"id": 413281864,
"term": "Lansing",
"definition": "Michigan",
"image": null
},
{
"id": 413281865,
"term": "St. Paul",
"definition": "Minnesota",
"image": null
},
{
"id": 413281866,
"term": "Jackson",
"definition": "Mississippi",
"image": null
},
{
"id": 413281867,
"term": "Jefferson City",
"definition": "Missouri",
"image": null
},
{
"id": 413281868,
"term": "Helena",
"definition": "Montana",
"image": null
},
{
"id": 413281869,
"term": "Lincoln",
"definition": "Nebraska",
"image": null
},
{
"id": 413281870,
"term": "Carson City",
"definition": "Nevada",
"image": null
},
{
"id": 413281871,
"term": "Concord",
"definition": "New Hampshire",
"image": null
},
{
"id": 413281872,
"term": "Trenton",
"definition": "New Jersey",
"image": null
},
{
"id": 413281873,
"term": "Santa Fe",
"definition": "New Mexico",
"image": null
},
{
"id": 413281874,
"term": "Albany",
"definition": "New York",
"image": null
},
{
"id": 413281875,
"term": "Raleigh",
"definition": "North Carolina",
"image": null
},
{
"id": 413281876,
"term": "Bismarck",
"definition": "North Dakota",
"image": null
},
{
"id": 413281877,
"term": "Columbus",
"definition": "Ohio",
"image": null
},
{
"id": 413281878,
"term": "Oklahoma City",
"definition": "Oklahoma",
"image": null
},
{
"id": 413281879,
"term": "Salem",
"definition": "Oregon",
"image": null
},
{
"id": 413281880,
"term": "Harrisburg",
"definition": "Pennsylvania",
"image": null
},
{
"id": 413281881,
"term": "Providence",
"definition": "Rhode Island",
"image": null
},
{
"id": 413281882,
"term": "Columbia",
"definition": "South Carolina",
"image": null
},
{
"id": 413281883,
"term": "Pierre",
"definition": "South Dakota",
"image": null
},
{
"id": 413281884,
"term": "Nashville",
"definition": "Tennessee",
"image": null
},
{
"id": 413281885,
"term": "Austin",
"definition": "Texas",
"image": null
},
{
"id": 413281886,
"term": "Salt Lake City",
"definition": "Utah",
"image": null
},
{
"id": 413281887,
"term": "Montpelier",
"definition": "Vermont",
"image": null
},
{
"id": 413281888,
"term": "Richmond",
"definition": "Virginia",
"image": null
},
{
"id": 413281889,
"term": "Olympia",
"definition": "Washington",
"image": null
},
{
"id": 413281890,
"term": "Charleston",
"definition": "West Virginia",
"image": null
},
{
"id": 413281891,
"term": "Madison",
"definition": "Wisconsin",
"image": null
},
{
"id": 413281892,
"term": "Cheyenne",
"definition": "Wyoming",
"image": null
}
]
You would use something like this to convert it to a NSDictionary:
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
Where data would be your response containing JSON. There may be some work involved to tailor up the json so that you get only the portion you want.
Here is my 'hint to where to search' : This is json, check for NSJSONSerialization tuto on the web.

Resources