Angular.js, node.js: require or import ? neither work for me :(

I am very new to Angular.js and node.js and I am facing a problem since this morning that has been partially solved. How to update a json file with data entered by a user via a form.

Thanks to some help that I got here, I managed to do that using lowdbwhich looks like an awesome dependency. The thing is, I can only make it work from a test file, like so:

1/ test.js (that I run node test.js)

const FileSync = require('lowdb/adapters/FileSync')

const dbFileName = "database/lexicon.json";
const adapter = new FileSync(dbFileName)
const db = low(adapter)

// Add another entry
db.get('entries')
.push({
    "title": "Here's a new entry",
    "topics": ["ajax", "rails"],
    "content": "This is very complicated",
    "link": "",
    "mainCategory": "Node.js"
    })
.write();

2/ Controller from where I would like it to work:

function EntryController ($http) {
    const ctrl = this;
    const API = '../database/lexicon.json';

    this.entry = {
    title: "",
    topics: [],
    content: "",
    link: "",
    mainCategory: ""
    };
    this.submitEntry = function () {
        
        const low = require('lowdb')
        const FileSync = require('lowdb/adapters/FileSync')
        
        const dbFileName = "database/lexicon.json";
        const adapter = new FileSync(dbFileName)
        const db = low(adapter)
        
        // Add another entry
        db.get('entries')
        .push({
            "title": "Number 1",
            "topics": ["ajax", "rails"],
            "content": "This is very complicated",
            "link": "",
            "mainCategory": "Node.js"
            })
        .write();
    };
};


angular
    .module('app')
    .controller('EntryController', EntryController);

But when running the app and submitting the form I get this error message require is not defined

I tried something similar with import but I get a similar error message: Cannot use import statement outside a module

Can anybody help?

Go to Source
Author: Olivier Girardot

How to get Json [object Object] type in Jsp?

actually I got that Json from Java to jsp.

$.ajax({
url:”MovieList.me”,
method:”get”,
dataType :”json”,
success:function(data){
$.each(data.Data,function(idx,item){

                    $.each(item.Result,function(idx,item2){
                        $.each(item2,function(idx,item3){
                         $('table').append("<tr><th>"+item3+"</th></tr>")
                        });
                      });

this is Jsp Jquery Code.

JsonParser jsonParser = new JsonParser();
JsonObject jsonObject = (JsonObject) jsonParser.parse(json);

this is java code and return jsonObject

Thank you for read

Go to Source
Author: ์ดํƒœ์œค

How to update the 3rd level of a json

I have a json file that looks like this

{
    "PL001": {
        "player_name": "Player 1",
        "player_email": "playeremail@email.com",
        "hobbies": {
          "SP001": {
            "sport": "Soccer",
            "positions": {
              "FL1":{
                "position": "Goalie"
              }
            }
          }
        }
    },
    "PL002": {
      "player_name": "Player 2",
      "player_email": "playeremail2@email.com",
      "hobbies": {
        "SP002": {
          "sport": "Hockey",
          "positions": {
            "FL2":{
              "position": "goaltender"
            }
          }
        }
      }
    }
}

What I need to do is change my positions codes to my new ones so for example my FL2 will be PLFL2

I’ve managed to get to the positions code but I’m not sure as to how I should go about pushing the new code up without loosing data.

Here is my codes

$old_code = "FL2";
$new_code = "PLFL2";


$json = json_decode(file_get_contents(storage_path('/players.json')));

$result = [];
foreach ($json as $key => $value)
{
  foreach($value->hobbies as $hobbiesCode => $hobby)
  {
    foreach ($hobby->positions as $positionCode => $position)
    {
      $positionCode = $new_code;
    }
  }
}

and that is where I get stuck. I’m not sure how to now go and update my json file with the new codes

Go to Source
Author: Aurilie

Doing a validation check on a AJAX post and returning the error message

I have an AJAX post that does this

  $.ajax({
                    type: "POST",
                    url: "@MyWebSite.Url/myController/myView",
                    contentType: "application/json; charset=utf-8",
                    data:
                    JSON.stringify({ myModel: myData }),
                    dataType: "json",
                    traditional: true,
                    success: function () {
                        alert('Success!');
                    },
                    error: function () {
                        alert('Error! ');
                    }

My controller does the validation check but it is not correctly returning the error message.
This is what my controller looks like

 if (totalQty < part.QtyInItem)
                    {
                        //ModelState.AddModelError("", "There is " + part.QtyInItem + " of Part " + part.PartName + " used in item " + part.ItemID + " but you only handled " + totalQty + ". Please verify you are handling all parts used in the item.");
                        //RedirectToAction("myControler", myModel);
                        return this.Json(new { success = false, message = "There is " + part.QtyInItem + " of Part " + part.PartName + " used in item " + part.ItemID + " but you only handled " + totalQty + ". Please verify you are handling all parts used in the item." });
                    }

When I tried adding an error to the model state it just returned “ERROR!” and not the error message I had associated with it. And when I try doing the this.JSON return it returns “success” to the view and not the error message.

How can I do this validation check for my AJAX post

Go to Source
Author: ryan

Perform SELECT using WHERE IN clause on JSON Object in MySQL

I have a json column in MySQL which contains a list of items for eg.

"style": {"style1", "style2", "style3", "style4", "style5"}

I want to search all the rows which contain the styles I specify through an array like IN clause like WHERE style IN(["style1", "style3"])

Is there any workaround or easy way to get this working?

Please help.. Thanks

Go to Source
Author: girish

postgresql error while using column values in jsonb_set function

I am trying to update a field value in jsonb column with text value present in another column but getting some syntax errors; not getting any solution.

i am trying to swap values of OutgoingVertexid & IncomingVertexId in below JSONB

'{
   "Owner":[
      {
         "Edgeid":10,
         "Weight":100,
         "Active":1,
         "OutgoingVertexid":"",
         "IncomingVertexid":"G",
         "EdgeColor":"Black"
      }
   ]
}'

so used below code by putting all values OutgoingVertexid & IncomingVertexid value in temp table.

UPDATE temp_table 
        SET 
        owner_property = CASE 
                            WHEN owner_outgoing_edge IS NOT NULL 
                                THEN jsonb_set(owner_property, '{OutgoingVertexid}', '""')
                            ELSE 
                                jsonb_set(owner_property, '{OutgoingVertexid}', ''||owner_incoming_edge::jsonb||'') 
                                END;

but getting below error:

ERROR: invalid input syntax for type json LINE 7: … jsonb_set(owner_property, ‘{OutgoingVertexid}’, ”””||ow… ^ DETAIL: Token “‘” is invalid.

If

Thanks in Advance

Go to Source
Author: VBAGuy

Architecture of optimized sync of JSON data to a (cloud) server

I’m building an application that generates JSON data based on the user’s notes. The notes are rich data that contain task lists and other types of elements inside it, so I use JSON format to store it. It currently saves this data to the browser’s local storage using JSON.stringify.

Now I’m building a feature that saves this data to a cloud server, but since the nature of the notes is that they constantly change, sending a big stringified object to the server at every note update (even if it has a 5-second debounce) seems a bit crazy to me. Depending on the size of the note, I’d have some 300kb calls or more to the server for a simple typo correction. Not good.

So I’ve looked into some services that support rich data JSON storage, such as Google’s Cloud Firestore or Amazon’s DynamoDB. Both look promising, but I’m still trying to wrap my head around my architecture for this. Here’s my plan so far:

  1. I’ll read the JSON from the server and keep a local object.
  2. At every local change, I’ll analyze the difference down the object tree and make some sort of diff string
  3. I’ll send only this diff string so the server can analyze and update its record.

Well, that seems to work. I would send a few bytes requests to the server, and not 300kb. It would require some code to analyze and generate the diff, but ok so far.

Now the server part is where my challenge is. Both Cloud Firestore and DynamoDB have rich data change functions, but it seems that for both, these operations must be pre-established according to the data itself, in other words, you must know the dataset in advance in order to make operations on it. Since my notes’ JSON are a dynamic dataset, I have no way of writing custom updates and inserts on it, it must be dynamically calculated via some sort of diff mechanism.

My questions are:

  1. Is this a good way to approach this problem or is there something I could be doing that would make things better/easier?
  2. Are there any cloud services, NoSQL databases, query languages, or libraries that would allow for this type of optimized dynamic JSON document update architecture?
  3. Would this be a good use case for GraphQL?

Go to Source
Author: raphadko