How check if there is an array or an object in jq?

Use the type function: type The type function returns the type of its argument as a string, which is one of null, boolean, number, string, array or object. Example 1: echo ‘[0, false, [], {}, null, “hello”]’ | jq ‘map(type)’ [ “number”, “boolean”, “array”, “object”, “null”, “string” ] Example 2: echo ‘[0,1]’ | jq ‘if … Read more

How to add a field to a JSON object with the jq command?

This type of update is where the magic of += comes into play. With your input, the following invocation: jq ‘.module.data.item_i77f664a2.fields += {“operation”:”delete”}’ produces the output you indicate you want: { “success”: true, “module”: { “data”: { “item_i77f664a2”: { “id”: “i77f664a2”, “tag”: “item”, “fields”: { “cartItemId”: 2012636322, “operation”: “delete” }, “type”: “biz” } } } … Read more

Why does Jackson polymorphic serialization not work in lists?

The various reasons for why this happens are discussed here and here. I don’t necessarily agree with the reasons, but Jackson, because of type erasure, doesn’t off the bat know the type of elements the List (or Collection or Map) contains. It chooses to use a simple serializer that doesn’t interpret your annotations. You have … Read more

What’s the use of Moshi’s Kotlin codegen?

This is sort of three questions Why is code gen useful Code gen is useful as a compile-time alternative to the reflective moshi-kotlin. Both of them are useful because they natively understand Kotlin code and its language features. Without them, Moshi would not be able to understand Kotlin nullability, default values, and much more. There … Read more

django postgresql json field schema validation

I wrote a custom validator using jsonschema in order to do this. project/validators.py import django from django.core.validators import BaseValidator import jsonschema class JSONSchemaValidator(BaseValidator): def compare(self, value, schema): try: jsonschema.validate(value, schema) except jsonschema.exceptions.ValidationError: raise django.core.exceptions.ValidationError( ‘%(value)s failed JSON schema check’, params={‘value’: value} ) project/app/models.py from django.db import models from project.validators import JSONSchemaValidator MY_JSON_FIELD_SCHEMA = { ‘schema’: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)