Defining a JSON schema with a nested array - arrays

I'm new to JSON so bear with me please (especially if I use the wrong terminology).
I'm trying to define a JSON schema with a nested array. The idea is that there could be up to 5 customers, and each customer could have up to 40 account types.
This is what I've defined, but I have a feeling it's incorrect. Could someone help me please ?
(I hope I've included enough of the relevant data to make sense)
"type":"object",
"properties":,
{
"customers":{
"description": "Contains up to 5 customers",
"type":"array",
"maxItems":5, /* Here are your 5 customers */
"minItems":0,
"items":{
"type":"object",
"properties":,
{
"customerid_cl":{
"description": "ID-KUNDNR",
"type":"integer",
"maximum":999999999,
"minimum":000000000
},
"ssn_number":{
"description": "id_persnr",
"type":"string",
"maxLength":12,
"minLength":12
},
"first_name":{
"description": "be_fnamn",
"type":"string",
"maxLength":15,
"minLength":15
},
"last_name":{
"description": "be_enamn",
"type":"string",
"maxLength":27,
"minLength":27
},
"deceased":{
"description": "FL-AVLIDEN",
"type":"boolean",
},
},
"Accounts":{
"description": "Contains up to 40 account types",
"type":"array",
"maxItems":40, /* and here are the 40 account types (potentially) for EACH customer */
"minItems":0,
"items":{
"type":"object",
"properties":,
{
"account_number":
{
"description": "id_kontonr",
"type":"string",
"maxLength":9,
"minLength":1
},
"currentbalance":
{
"description": "Current account balance - how do we indicate that negative values are okay ????",
"type": "number",
"format":"decimal",
"maximum":999999999.99,
"minimum":-999999999.99
},**strong text**

Related

I am trying to create discord embeds, I do not know why this embed is working

Here is the code
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
await lib.discord.channels['#0.3.2'].messages.create({
"channel_id": ${context.params.event.channel_id},
"content": "",
"tts": false,
"embeds": [
{
"type": "rich",
"title": Staff Guidebook!,
"description": Here you can find the **punishment guide** and the **commands lists** to assist you!,
"color": 0xff0000,
"fields": [
{
"name": Dyno Commands List,
"value": https://dyno.gg/commands,
"inline": true
},
{
"name": Staff Punishment Guide,
"value": https://docs.google.com/spreadsheets/d/15JoaAvjOqaFDATEG91lS1UPOY-8gMIO112-kif2oiB8/edit?usp=sharing,
"inline": true
},
{
"name": Staffing Rules,
"value": - Staff cannot moderate other staff, you must create a support ticket instead.\n- You mut be as helpful as possible at all times.\n- You do not have to be proffesional at all times however when dealing with a staff \nsituation (aka. tickets) you must remain proffesional and use grammer at all times.\n- Being staff does not stop you from being within our rules. Any staff who break rules \nwill be punished accordingly by our support team.\n- You cannot leak any punishments or staff only information to other people, this can result in your removal from the staff team.\n- Keep calm when dealing with situations.\n- Always have evidence ready if you are going to punish someone.,
"inline": true
}
]
}
]
});
When I put it in, it comes out like a normal text message.

How does a predefined slot return a resolution?

I'm building a simple Guess Who skill game for Alexa. I have two intents right now: GenderIntent and HairColorIntent.
GenderIntent has a custom slot to handle gender and related synonyms such as mapping "boy" and "man" to "Male". This is working great. It returns a resolution within the slot. Exactly what I need.
HairColorIntent has a predefined Amazon slot, AMAZON.Color. This is not working great as it never returns a resolution regardless of the color supplied.
Here is my model for GenderIntent and HairColorIntent:
{
"name": "GenderIntent",
"samples": [
"are you a {Gender}"
],
"slots": [
{
"name": "Gender",
"type": "GENDER_TYPES",
"samples": []
}
]
},
{
"name": "HairColorIntent",
"samples": [
"is your hair {HairColor}",
"do you have {HairColor} hair"
],
"slots": [
{
"name": "HairColor",
"type": "AMAZON.Color"
}
]
}
GenderIntent returns the following slot WITH resolutions:
{
"Gender": {
"name": "Gender",
"value": "male",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.2ed972f4-1c5a-4cc1-8fd7-3f440f5b8968.GENDER_TYPES",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "Male",
"id": "63889cfb9d3cbe05d1bd2be5cc9953fd"
}
}
]
}
]
},
"confirmationStatus": "NONE",
"source": "USER"
}
}
HairColorIntent returns the following WITHOUT resolutions:
{
"HairColor": {
"name": "HairColor",
"value": "brown",
"confirmationStatus": "NONE",
"source": "USER"
}
}
I'd like HairColorIntent's HairColor slot to return the resolution. What am I doing wrong?
Resolution is only returned if you use synonyms in your slot type.
Not exactly sure how you handle it in your code, for example Node.js would be:
handlerInput.requestEnvelope.request.intent.slots.Gender.resolutions.resolutionPerAuthority[0].values[0].value.name
If you do not use synonyms (for example for the HairColor slot), you can get the value simply by handlerInput.requestEnvelope.request.intent.slots.HairColor.value
Working with predefined slot types this should work well with your code. If you want custom slot types to also return resolution whether you actually use synonyms or not, you can always just simply give the value as a synonym and it should return the full resolution tree.
Hope that answered your question.

Cannot set SKU using Quickbooks API

I’m trying to create an item using the Quickbooks Online API, but the field Sku is just ignored. I send a body like this:
{
"TrackQtyOnHand": true,
"Name": "Garden Supplies",
"Sku": "ITEM-1",
"QtyOnHand": 10,
"IncomeAccountRef": {
"name": "Sales of Product Income",
"value": "79"
},
"AssetAccountRef": {
"name": "Inventory Asset",
"value": "81"
},
"InvStartDate": "2015-01-01",
"Type": "Inventory",
"ExpenseAccountRef": {
"name": "Cost of Goods Sold",
"value": "80"
}
}
However in the object I get back as response, the Sku field is not there.
I set the parameter minorVersion to 45 (which is something I was suggested to do), but still not working.
I think the problem is that the param minorVersion should actually be minorversion (all lowercase).

Ruby - parse JSON file with nested arrays to ruby hash without data loss

I have a file1.json with structure like this :
[
{
"uri": "features/hdp.feature",
"id": "as-a-user-i-want-to-use-house-detailed-page",
"keyword": "Feature",
"name": "As a user I want to use house detailed page",
"description": "",
"line": 2,
"tags": [
{
"name": "#hdp",
"line": 1
}
],
"elements": [
{
As you can see - it is an array with nested key:value pairs and other arrays. I need to convert it to ruby hash, but when I'm performing JSON.parse(file1) - it creates an array (http://prntscr.com/lqio6r) with ruby hashes, arrays and so on. If I'm performing JSON.parse(file1).reduce Hash.new, :merge or JSON.parse(file1).reduce Hash.new, :update) - as one of the answers on StackOverflow supposed - the result hash losses about 60% of .json content. Can you please advice on how can I convert json file to ruby hash (without any data losses)?
UPD - not truncated array - https://gist.githubusercontent.com/M1khah/3337507e3ca1544e6098bc726bca90cb/raw/c8262ad753bd0eebf1180e111acd016ffc07d1a5/gistfile1.txt
Hash with hashes - something like this instead of an array with nested hashes
{
{
"uri": "features/hdp.feature",
"id": "as-a-user-i-want-to-use-house-detailed-page",
"keyword": "Feature",
"name": "As a user I want to use house detailed page",
"description": "",
"line": 2,
"tags": [
{
"name": "#hdp",
"line": 1
}
],
"elements": [
{
}

Concatenation of JSON Arrays/Objects using Groovy

How can two independent different JSON Arrays or JSON Objects be merged or concatenated and treated as a single JSON Object using Java or Groovy.
See below sample JSON independent Objects i have
First one holds Duties information
[
{
"code": "A0001",
"description": "Do strategic planning for long range goals of the university"
},
{
"code": "A0002",
"description": "Administer budgets in excess of 1,000,000"
}]
Second JSON object holds Certificates infomation
[
{
"code": "CPA",
"description": "Certified Public Accountant"
},
{
"code": "CPR",
"description": "Cardiopulmonary Resuscitation"
},
{
"code": "ELE",
"description": "Electrician's License"
}]
I need to concatenate and access both the JSONs in below format `
{
"duties":
[{
"code": "A0001",
"description": "Do strategic planning for long range goals of the university"
},
{
"code": "A0002",
"description": "Administer budgets in excess of 1,000,000"
}],
"Certificates":
[
{
"code": "CPA",
"description": "Certified Public Accountant"
},
{
"code": "CPR",
"description": "Cardiopulmonary Resuscitation"
},
{
"code": "ELE",
"description": "Electrician's License"
}
]
}
Please let me know the option available to get this done. Thanks
It can be done e.g. in the following way:
import groovy.json.*
def json1 = """[
{
"code": "A0001",
"description": "Do strategic planning for long range goals of the university"
},
{
"code": "A0002",
"description": "Administer budgets in excess of 1,000,000"
}]"""
def json2 = """[
{
"code": "CPA",
"description": "Certified Public Accountant"
},
{
"code": "CPR",
"description": "Cardiopulmonary Resuscitation"
},
{
"code": "ELE",
"description": "Electrician's License"
}]"""
def duties = new JsonSlurper().parseText(json1)
def certs = new JsonSlurper().parseText(json2)
println JsonOutput.prettyPrint(JsonOutput.toJson ([duties: duties, certificates: certs]))

Resources