1

I'm trying to Create a specific Syntax for POST Request.

That is, using Javascript to Create the specified Array Structure based on certain data.

Data : Array of Objects. Each Object represents a row in a Table. Those rows, have an ID Key, that can be found on More that one Row.

POST Request : Create the Below POST Request Syntax:

  1. For Each Unique Row ID, create the P1 Section. (This Object Represents each Unique ID )

    • If ID is entered more that once, do not create more P1 Sections with same ID. P1 is already created for this ID.
  2. For each of these unique IDs, get its Row Details and place them in Section P2.

    • If Unique IDs rows are more that one, create multiple P2 Sections for the Specific ID.

[ [

  P1 -   {
          "Swee": "Cont",
          "Time": 33,
          "ID": 10,
          "Configs": [
    P2 -            {
                     "VAL": "VALUE"
    P2 -            }
           ]
  P1 -   }

] ] Please, anyone can help please do.

4
  • 2
    what language is running on the server? Build up a response object in that lang, then serialize to JSON in the web response to get valid JSON. Commented Apr 16, 2019 at 18:03
  • 1
    I’m using Vue JS and bootstrap-vue Tables specifically. Commented Apr 16, 2019 at 18:04
  • 1
    The API that accepts POST is created with Python Commented Apr 16, 2019 at 18:05
  • 1
    @KyriakosMichael Show us that python code, then, please. How to create a response to a POST request has nothing to with your clientside javascript stack. Commented Apr 16, 2019 at 18:27

1 Answer 1

1

I would recommend the following: 1. Iterate over your data and filter what you need, simplest is to use lodash try this method for your needs: https://lodash.com/docs/4.17.11#uniqBy 2. You can deconstruct properties and elements from an object or array like this this: const { property1, property2, property3 } = this.myData this exposes these properties from your data (stored in myData in this example), now you can restructure them as you wish for example: paylod : { property1: { property2 }, property3 } here my payload object now has a new nested structure. In your question you do not provide enough info for me to do this but this would be a direction to take. Hope this helps

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.