Questions tagged [jsonencoder]

Use this tag for `JSONEncoder` questions on Apple platforms.

JSONEncoder is a class, introduced in Swift 4, for encoding types on Apple operating systems that conform to Encodable protocol (or Codable protocol, which is type alias for Encodable & Decodable). This offers a simple mechanism to easily generate JSON from Encodable Swift types. This applies to standard Swift collections, such as Array and Dictionary, but custom types can conform to Encodable to participate in this simplified JSON encoding process.

This replaces/supplements the JSONSerialiation class used in prior Swift versions.

See also:

125 questions
2
votes
0 answers

Use encoding function only in specific cases

I have struct that conforms to the Codable-protocol. I implemented a custom encode-func so that I have control over the encoding process. But I don't need this custom encoding in all cases, sometimes I want to rely on the encoding of Foundation…
Lupurus
  • 3,618
  • 2
  • 29
  • 59
2
votes
3 answers

How to convert a PHP array into json string

I have a PHP array built with a while loop. I do successfully convert it to JSON string, however the output is not what I want and need some help to get it right: My current code: while(!$sql_query->EOF){ $data[] = array( 'id' …
user3132858
  • 609
  • 1
  • 11
  • 27
2
votes
1 answer

How to maintain object state after JSON Encode/Decode in PHP

The below method have changed property instance in object into array but the requirement have different, the result of response will be same required after manipulation. 200, …
Query Master
  • 6,989
  • 5
  • 35
  • 58
2
votes
1 answer

How to get proper json?

I don't know php and JSON i wanted a result like below How to add array employeelist on my json { "employeeList": [ { "name": "Gretchen Rodriquez", "email": "gretchenrodriquez@trasola.com" }, { "name": "Sharon…
Annabelle
  • 59
  • 1
  • 9
1
vote
2 answers

How to make json keys as a special order in Swift JSONEncoder?

I need make a request to a server of an open API. The rule of the open API asked json parameter must make keys as a special order(not the A-Z order nor Z-A order). struct Req : Encodable { let SourceText: String let Target: String let…
boybeak
  • 417
  • 5
  • 19
1
vote
1 answer

"Cannot convert value of type to expected dictionary value type 'JSONEncodable?'" for Apollo iOS

I'm struggling with using "custom scalar" for my GraphQL Apollo iOS App. I want to get "Timestamp" as "UInt64" so I followed solution written on Apollo Tutorial. Codeine to API.swift seems using Timestamp, which is custom scalar. But there's error…
Dan Choi
  • 83
  • 2
  • 8
1
vote
1 answer

How to encode enum with Arrays of Custom Objects

Thanks for your help in advance! I am relatively new to SwiftUI and have been struggling with encoding an enum with Arrays of custom objects. Here is the code: struct ChartData: Codable { var data: DataType ... private enum CodingKeys :…
1
vote
2 answers

How do I convert a dictionary to top level JSON in Swift?

I have this model in Swift: struct EventModel: Codable { var eventType: String var eventName: String? var attributes: [String: String]? } Is it possible to move the attributes to the top level when I convert it to JSON? Example: var…
colbrew
  • 69
  • 8
1
vote
1 answer

how to pass jsonEncode http post?

i got all the parameters jsonEncode then i will pass http post. i have explained below the via source code. var abc = jsonEncode({ "requisitionID": "x", "RetailerTitle": "Faruqe Ahmed Store", "RetailerAddress" : "Dhaka…
1
vote
2 answers

Terraform template jsonencoding with iterate

I'm looking for a solution for this template to get the correct JSON file. As you may see in the sections, aws:RequestTag/*** lacks commas at the end. If I use the comma in the template, then I will have an unnecessary comma at the end of the last…
1
vote
1 answer

Another Invalid top-level type in JSON write crash

So, Xcode 13.1, iOS 15.0, I am stuck with this JSON serialization for a rather important project which has to be delivered yesterday(!) as usual, and instead crashes. This is the piece of code I'm dealing with: var jsonData: Data do { …
Fabrizio Prosperi
  • 1,398
  • 4
  • 18
  • 32
1
vote
1 answer

AWS - Terraform - SCP - MalformedPolicyDocumentException

resource "aws_organizations_policy" "tag_enforcement_eks" { name = "tag_enforcement_eks" content = <
1
vote
1 answer

Invalid JSON when using jsonencode in Terraform

I am creating some AWS Config rules using Terraform version 0.14.5. I am defining the resources using the for_each method shown below. I am getting an error stating my JSON is invalid. I have used tools such as JSONlint to validate my JSON, but I am…
Dave Michaels
  • 847
  • 1
  • 19
  • 51
1
vote
1 answer

GCP Firestore document db creation using terraform

I am using terraform resource google_firestore_document to create firestor document db and i was abel to create it successfully. I am trying to convert it to a module for which I need to build the values in jsonencode format. example: ` + fields …
1
vote
0 answers

Symfony Serializer deserialize array into ORM OneToMany relation

In a Symfony 5 project I get this error Failed to denormalize attribute "options" value for class "App\Entity\Configuration": Expected argument of type "App\Entity\Option", "array" given at property path "options". when trying to deserialize a…
1
2
3
8 9